Compare commits

...

3 Commits

Author SHA1 Message Date
b223361e54 added makefile 2021-12-01 11:02:07 +01:00
9c0346bc61 use screen size constants directly... 2021-11-30 23:21:47 +01:00
bab32fa68d moar comments, moar constants 2021-11-30 22:58:01 +01:00
10 changed files with 65 additions and 46 deletions

2
.gitignore vendored
View File

@@ -1,2 +1,2 @@
Build Build
rom.sym *.sym

View File

@@ -1,5 +1,6 @@
INCLUDE "hardware.inc" INCLUDE "hardware.inc"
INCLUDE "automata.inc"
BUFFER_SIZE = SCRN_X_B * SCRN_Y_B
; automata buffers with 4 cells per byte ; automata buffers with 4 cells per byte
; 2x2 bytes per cell, bit ordering: ; 2x2 bytes per cell, bit ordering:
@@ -157,19 +158,19 @@ SECTION "Update Automata", ROM0
UpdateAutomata: UpdateAutomata:
.topleft .topleft
; handle top left corner ; handle top left corner
ConwayGroup 1, (TILE_WIDTH + 1), TILE_WIDTH, (2 * TILE_WIDTH - 1), (TILE_WIDTH - 1), (BUFFER_SIZE - 1), (BUFFER_SIZE - TILE_WIDTH), (BUFFER_SIZE - TILE_WIDTH + 1) ConwayGroup 1, (SCRN_X_B + 1), SCRN_X_B, (2 * SCRN_X_B - 1), (SCRN_X_B - 1), (BUFFER_SIZE - 1), (BUFFER_SIZE - SCRN_X_B), (BUFFER_SIZE - SCRN_X_B + 1)
; advance to next cell in top row ; advance to next cell in top row
ld hl, Progress ld hl, Progress
inc [hl] inc [hl]
; handle all cells in top row except corners ; handle all cells in top row except corners
ld a, (TILE_WIDTH - 2) ld a, (SCRN_X_B - 2)
.top .top
ld [XLoop], a ld [XLoop], a
; handle top row cell ; handle top row cell
ConwayGroup 1, (TILE_WIDTH + 1), TILE_WIDTH, (TILE_WIDTH - 1), -1, (BUFFER_SIZE - TILE_WIDTH - 1), (BUFFER_SIZE - TILE_WIDTH), (BUFFER_SIZE - TILE_WIDTH + 1) ConwayGroup 1, (SCRN_X_B + 1), SCRN_X_B, (SCRN_X_B - 1), -1, (BUFFER_SIZE - SCRN_X_B - 1), (BUFFER_SIZE - SCRN_X_B), (BUFFER_SIZE - SCRN_X_B + 1)
; advance to next cell in top row ; advance to next cell in top row
ld hl, Progress ld hl, Progress
@@ -182,18 +183,18 @@ UpdateAutomata:
; handle top right corner ; handle top right corner
.topright .topright
ConwayGroup (-TILE_WIDTH + 1), 1, TILE_WIDTH, (TILE_WIDTH - 1), -1, (BUFFER_SIZE - TILE_WIDTH - 1), (BUFFER_SIZE - TILE_WIDTH), (BUFFER_SIZE - 2 * TILE_WIDTH + 1) ConwayGroup (-SCRN_X_B + 1), 1, SCRN_X_B, (SCRN_X_B - 1), -1, (BUFFER_SIZE - SCRN_X_B - 1), (BUFFER_SIZE - SCRN_X_B), (BUFFER_SIZE - 2 * SCRN_X_B + 1)
; advance pointers to next row ; advance pointers to next row
ld hl, Progress ld hl, Progress
inc [hl] inc [hl]
ld a, (TILE_HEIGHT - 2) ld a, (SCRN_Y_B - 2)
.leftcolumn .leftcolumn
ld [YLoop], a ld [YLoop], a
; handle first element in row ; handle first element in row
ConwayGroup 1, (TILE_WIDTH + 1), TILE_WIDTH, (2 * TILE_WIDTH - 1), (TILE_WIDTH - 1), -1, (-TILE_WIDTH), (-TILE_WIDTH + 1) ConwayGroup 1, (SCRN_X_B + 1), SCRN_X_B, (2 * SCRN_X_B - 1), (SCRN_X_B - 1), -1, (-SCRN_X_B), (-SCRN_X_B + 1)
; advance to next cell ; advance to next cell
ld hl, Progress ld hl, Progress
@@ -204,7 +205,7 @@ UpdateAutomata:
ld [XLoop], a ld [XLoop], a
; handle element inside row ; handle element inside row
ConwayGroup 1, (TILE_WIDTH + 1), TILE_WIDTH, (TILE_WIDTH - 1), -1, (-TILE_WIDTH - 1), (-TILE_WIDTH), (-TILE_WIDTH + 1) ConwayGroup 1, (SCRN_X_B + 1), SCRN_X_B, (SCRN_X_B - 1), -1, (-SCRN_X_B - 1), (-SCRN_X_B), (-SCRN_X_B + 1)
; advance to next cell ; advance to next cell
ld hl, Progress ld hl, Progress
@@ -223,7 +224,7 @@ UpdateAutomata:
; handle last element in row ; handle last element in row
.rightcolumn .rightcolumn
ConwayGroup (-TILE_WIDTH + 1), 1, TILE_WIDTH, (TILE_WIDTH - 1), -1, (-TILE_WIDTH - 1), -TILE_WIDTH, (-2 * TILE_WIDTH + 1) ConwayGroup (-SCRN_X_B + 1), 1, SCRN_X_B, (SCRN_X_B - 1), -1, (-SCRN_X_B - 1), -SCRN_X_B, (-2 * SCRN_X_B + 1)
; advance to next row ; advance to next row
ld hl, Progress ld hl, Progress
@@ -236,19 +237,19 @@ UpdateAutomata:
; handle bottom left element ; handle bottom left element
.bottomleft .bottomleft
ConwayGroup 1, (-BUFFER_SIZE + TILE_WIDTH + 1), (-BUFFER_SIZE + TILE_WIDTH), (-BUFFER_SIZE + 2 * TILE_WIDTH - 1), (TILE_WIDTH - 1), -1, (-TILE_WIDTH), (-TILE_WIDTH + 1) ConwayGroup 1, (-BUFFER_SIZE + SCRN_X_B + 1), (-BUFFER_SIZE + SCRN_X_B), (-BUFFER_SIZE + 2 * SCRN_X_B - 1), (SCRN_X_B - 1), -1, (-SCRN_X_B), (-SCRN_X_B + 1)
; advance to next cell in bottom row ; advance to next cell in bottom row
ld hl, Progress ld hl, Progress
inc [hl] inc [hl]
; handle all cells in bottom row except corners ; handle all cells in bottom row except corners
ld a, TILE_WIDTH - 2 ld a, SCRN_X_B - 2
.bottom .bottom
ld [XLoop], a ld [XLoop], a
; handle top row cell ; handle top row cell
ConwayGroup 1, (-BUFFER_SIZE + TILE_WIDTH + 1), (-BUFFER_SIZE + TILE_WIDTH), (-BUFFER_SIZE + TILE_WIDTH - 1), -1, (-TILE_WIDTH - 1), (-TILE_WIDTH), (-TILE_WIDTH + 1) ConwayGroup 1, (-BUFFER_SIZE + SCRN_X_B + 1), (-BUFFER_SIZE + SCRN_X_B), (-BUFFER_SIZE + SCRN_X_B - 1), -1, (-SCRN_X_B - 1), (-SCRN_X_B), (-SCRN_X_B + 1)
; advance to next cell in top row ; advance to next cell in top row
ld hl, Progress ld hl, Progress
@@ -261,7 +262,7 @@ UpdateAutomata:
; handle last element ; handle last element
.bottomright .bottomright
ConwayGroup (-TILE_WIDTH + 1), (-BUFFER_SIZE + 1), (-BUFFER_SIZE + TILE_WIDTH), (-BUFFER_SIZE + TILE_WIDTH - 1), -1, (-TILE_WIDTH - 1), (-TILE_WIDTH), (-2 * TILE_WIDTH + 1) ConwayGroup (-SCRN_X_B + 1), (-BUFFER_SIZE + 1), (-BUFFER_SIZE + SCRN_X_B), (-BUFFER_SIZE + SCRN_X_B - 1), -1, (-SCRN_X_B - 1), (-SCRN_X_B), (-2 * SCRN_X_B + 1)
; move buffer address back to beginning ; move buffer address back to beginning
ld hl, Old ld hl, Old

View File

@@ -1,6 +0,0 @@
CELLS_WIDTH = 40
CELLS_HEIGHT = 36
CELLS_PER_TILE = 2
TILE_WIDTH = CELLS_WIDTH / CELLS_PER_TILE
TILE_HEIGHT = CELLS_HEIGHT / CELLS_PER_TILE
BUFFER_SIZE = TILE_WIDTH * TILE_HEIGHT

View File

@@ -23,7 +23,7 @@ BitsSet:
EXPORT DefaultMap EXPORT DefaultMap
SECTION "Default Map", ROM0, ALIGN[8] SECTION "Default Map", ROM0, ALIGN[8]
DefaultMap: DefaultMap:
; 32x18 map matching the startup nintendo logo ; 32x18 game of life map matching the startup nintendo logo
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

View File

@@ -1,6 +1,5 @@
INCLUDE "hardware.inc" INCLUDE "hardware.inc"
INCLUDE "utils.inc" INCLUDE "utils.inc"
INCLUDE "automata.inc"
SPRITE_ANIM_DELAY EQU 6 SPRITE_ANIM_DELAY EQU 6
REPEAT_START_DELAY EQU 16 REPEAT_START_DELAY EQU 16
@@ -17,9 +16,9 @@ SpriteDelay: ds 1
EXPORT InitEdit EXPORT InitEdit
SECTION "Init edit", ROM0 SECTION "Init edit", ROM0
InitEdit: InitEdit:
ld a, TILE_WIDTH ld a, SCRN_X_B
ldh [SelectX], a ldh [SelectX], a
ld a, TILE_HEIGHT ld a, SCRN_Y_B
ldh [SelectY], a ldh [SelectY], a
xor a xor a
ldh [Down], a ldh [Down], a
@@ -223,7 +222,7 @@ ToggleCell:
ld l, a ld l, a
ldh a, [Old] ldh a, [Old]
ld h, a ld h, a
MoveToCell TILE_WIDTH MoveToCell SCRN_X_B
; toggle bit ; toggle bit
ld a, [hl] ld a, [hl]
@@ -272,7 +271,7 @@ Clear:
ld [Rendered + 1], a ld [Rendered + 1], a
; clear old buffer ; clear old buffer
ld bc, TILE_WIDTH * TILE_HEIGHT ld bc, SCRN_X_B * SCRN_Y_B
ld d, 0 ld d, 0
call MemorySet call MemorySet

View File

@@ -44,7 +44,8 @@ Intro:
jr z, .setBGPalette jr z, .setBGPalette
; fade bg palette ; fade bg palette
ld b, 8 FADE_DELAY = 8 ; frames
ld b, FADE_DELAY
.fadeDelay0 .fadeDelay0
HaltAndClearInterrupts HaltAndClearInterrupts
dec b dec b
@@ -53,7 +54,7 @@ Intro:
ld a, %11111100 ld a, %11111100
ldh [rBGP], a ldh [rBGP], a
ld b, 8 ld b, FADE_DELAY
.fadeDelay1 .fadeDelay1
HaltAndClearInterrupts HaltAndClearInterrupts
dec b dec b
@@ -62,7 +63,7 @@ Intro:
ld a, %11111000 ld a, %11111000
ldh [rBGP], a ldh [rBGP], a
ld b, 8 ld b, FADE_DELAY
.fadeDelay2 .fadeDelay2
HaltAndClearInterrupts HaltAndClearInterrupts
dec b dec b
@@ -127,7 +128,7 @@ Intro:
ld a, LCDCF_ON | LCDCF_BGON | LCDCF_BG9800 ld a, LCDCF_ON | LCDCF_BGON | LCDCF_BG9800
ldh [rLCDC], a ldh [rLCDC], a
; sound ; sweep sound while transforming nintendo logo into game of life of it
ld a, $77 ld a, $77
ldh [rNR10], a ; sweep ldh [rNR10], a ; sweep
ld a, (%00 << 6) + 0 ld a, (%00 << 6) + 0
@@ -146,22 +147,23 @@ FREQUENCY = 146
ld b, 20 ld b, 20
.loopX .loopX
ld c, 2 ld c, 2
; 3 frame delay
HaltAndClearInterrupts HaltAndClearInterrupts
HaltAndClearInterrupts HaltAndClearInterrupts
HaltAndClearInterrupts HaltAndClearInterrupts
.loopY .loopY
; copy 8 tiles (that's how many there is before L and E overflow) ; copy 8 tiles from (that's how many there is before L and E overflow)
REPT 8 REPT 8
ld a, [hl] ld a, [hl]
ld [de], a ld [de], a
ld a, l ld a, l
add a, $20 add a, SCRN_VX_B
ld l, a ld l, a
ld a, e ld a, e
add a, $20 add a, SCRN_VX_B
ld e, a ld e, a
ENDR ENDR
; L and E overflowed, we can increment H and L ; L and E overflowed, we can increment high byte of pointers (h and d)
inc h inc h
inc d inc d
dec c dec c
@@ -171,10 +173,10 @@ REPT 2
ld a, [hl] ld a, [hl]
ld [de], a ld [de], a
ld a, l ld a, l
add a, $20 add a, SCRN_VX_B
ld l, a ld l, a
ld a, e ld a, e
add a, $20 add a, SCRN_VX_B
ld e, a ld e, a
ENDR ENDR
; back to beginning (high byte) ; back to beginning (high byte)
@@ -187,10 +189,10 @@ ENDR
; back to beginning + next column (low byte) ; back to beginning + next column (low byte)
ld a, l ld a, l
sub a, $3F sub a, SCRN_VX_B * 2 - 1
ld l, a ld l, a
ld a, e ld a, e
sub a, $3F sub a, SCRN_VX_B * 2 - 1
ld e, a ld e, a
dec b dec b

View File

@@ -75,9 +75,9 @@ ENDR
; copy default map into 20x18 automata buffer ; copy default map into 20x18 automata buffer
ld hl, DefaultMap ld hl, DefaultMap
ld de, Buffer0 ld de, Buffer0
ld c, 18 ld c, SCRN_Y_B
.loopY .loopY
ld b, 20 ld b, SCRN_X_B
.loopX .loopX
ld a, [hl+] ld a, [hl+]
@@ -90,7 +90,7 @@ ENDR
jr z, .next jr z, .next
ld a, l ld a, l
add a, 32 - 20 add a, SCRN_VX_B - SCRN_X_B
ld l, a ld l, a
jr nc, .loopY jr nc, .loopY

View File

@@ -1,6 +1,5 @@
INCLUDE "hardware.inc" INCLUDE "hardware.inc"
INCLUDE "utils.inc" INCLUDE "utils.inc"
INCLUDE "automata.inc"
RENDER_IN_HBL EQU 0 RENDER_IN_HBL EQU 0
@@ -72,7 +71,7 @@ LCDStatInterruptHandler:
; go to next line ; go to next line
ld a, e ld a, e
add a, SCRN_VX_B - TILE_WIDTH add a, SCRN_VX_B - SCRN_X_B
ld e, a ld e, a
jr nc, .nocarry jr nc, .nocarry
inc d inc d
@@ -83,7 +82,7 @@ LCDStatInterruptHandler:
jr z, .finish jr z, .finish
; reset tile counter ; reset tile counter
ld c, TILE_WIDTH ld c, SCRN_X_B
jr .loop jr .loop
@@ -137,9 +136,9 @@ StartRender:
ld [Rendered + 1], a ld [Rendered + 1], a
; start rendering ; start rendering
ld a, TILE_WIDTH ld a, SCRN_X_B
ldh [TilesLeft], a ldh [TilesLeft], a
ld a, TILE_HEIGHT ld a, SCRN_Y_B
ldh [LinesLeft], a ldh [LinesLeft], a
; enable v-blank and lcd stat interrupt for h-blank ; enable v-blank and lcd stat interrupt for h-blank

Binary file not shown.

24
Makefile Normal file
View File

@@ -0,0 +1,24 @@
TITLE = "Game of Life"
INCLUDE = -i Graphics -i Code
NAME = $(notdir $(CURDIR))
FILES = $(wildcard Code/*.asm)
OBJECTS = $(patsubst Code/%.asm,Build/%.o,$(FILES))
.PHONY: clean mrproper
Build/%.o: Code/%.asm
@echo Assembling $<
@rgbasm $(INCLUDE) -o $@ $<
$(NAME).gb: $(OBJECTS)
@echo Linking...
@rgblink -n $(NAME).sym -w -t -o $(NAME).gb -d $(OBJECTS)
@rgbfix -t $(TITLE) -v -p 0 $(NAME).gb
clean:
@rm -f $(OBJECTS)
@rm -f $(NAME).sym
mrproper: clean
@rm -f $(NAME).gb