Compare commits
3 Commits
0a2eef8336
...
b223361e54
| Author | SHA1 | Date | |
|---|---|---|---|
| b223361e54 | |||
| 9c0346bc61 | |||
| bab32fa68d |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,2 @@
|
||||
Build
|
||||
rom.sym
|
||||
*.sym
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
INCLUDE "hardware.inc"
|
||||
INCLUDE "automata.inc"
|
||||
|
||||
BUFFER_SIZE = SCRN_X_B * SCRN_Y_B
|
||||
|
||||
; automata buffers with 4 cells per byte
|
||||
; 2x2 bytes per cell, bit ordering:
|
||||
@@ -157,19 +158,19 @@ SECTION "Update Automata", ROM0
|
||||
UpdateAutomata:
|
||||
.topleft
|
||||
; 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
|
||||
ld hl, Progress
|
||||
inc [hl]
|
||||
|
||||
; handle all cells in top row except corners
|
||||
ld a, (TILE_WIDTH - 2)
|
||||
ld a, (SCRN_X_B - 2)
|
||||
.top
|
||||
ld [XLoop], a
|
||||
|
||||
; 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
|
||||
ld hl, Progress
|
||||
@@ -182,18 +183,18 @@ UpdateAutomata:
|
||||
|
||||
; handle top right corner
|
||||
.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
|
||||
ld hl, Progress
|
||||
inc [hl]
|
||||
|
||||
ld a, (TILE_HEIGHT - 2)
|
||||
ld a, (SCRN_Y_B - 2)
|
||||
.leftcolumn
|
||||
ld [YLoop], a
|
||||
|
||||
; 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
|
||||
ld hl, Progress
|
||||
@@ -204,7 +205,7 @@ UpdateAutomata:
|
||||
ld [XLoop], a
|
||||
|
||||
; 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
|
||||
ld hl, Progress
|
||||
@@ -223,7 +224,7 @@ UpdateAutomata:
|
||||
|
||||
; handle last element in row
|
||||
.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
|
||||
ld hl, Progress
|
||||
@@ -236,19 +237,19 @@ UpdateAutomata:
|
||||
|
||||
; handle bottom left element
|
||||
.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
|
||||
ld hl, Progress
|
||||
inc [hl]
|
||||
|
||||
; handle all cells in bottom row except corners
|
||||
ld a, TILE_WIDTH - 2
|
||||
ld a, SCRN_X_B - 2
|
||||
.bottom
|
||||
ld [XLoop], a
|
||||
|
||||
; 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
|
||||
ld hl, Progress
|
||||
@@ -261,7 +262,7 @@ UpdateAutomata:
|
||||
|
||||
; handle last element
|
||||
.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
|
||||
ld hl, Old
|
||||
|
||||
@@ -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
|
||||
@@ -23,7 +23,7 @@ BitsSet:
|
||||
EXPORT DefaultMap
|
||||
SECTION "Default Map", ROM0, ALIGN[8]
|
||||
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
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
INCLUDE "hardware.inc"
|
||||
INCLUDE "utils.inc"
|
||||
INCLUDE "automata.inc"
|
||||
|
||||
SPRITE_ANIM_DELAY EQU 6
|
||||
REPEAT_START_DELAY EQU 16
|
||||
@@ -17,9 +16,9 @@ SpriteDelay: ds 1
|
||||
EXPORT InitEdit
|
||||
SECTION "Init edit", ROM0
|
||||
InitEdit:
|
||||
ld a, TILE_WIDTH
|
||||
ld a, SCRN_X_B
|
||||
ldh [SelectX], a
|
||||
ld a, TILE_HEIGHT
|
||||
ld a, SCRN_Y_B
|
||||
ldh [SelectY], a
|
||||
xor a
|
||||
ldh [Down], a
|
||||
@@ -223,7 +222,7 @@ ToggleCell:
|
||||
ld l, a
|
||||
ldh a, [Old]
|
||||
ld h, a
|
||||
MoveToCell TILE_WIDTH
|
||||
MoveToCell SCRN_X_B
|
||||
|
||||
; toggle bit
|
||||
ld a, [hl]
|
||||
@@ -272,7 +271,7 @@ Clear:
|
||||
ld [Rendered + 1], a
|
||||
|
||||
; clear old buffer
|
||||
ld bc, TILE_WIDTH * TILE_HEIGHT
|
||||
ld bc, SCRN_X_B * SCRN_Y_B
|
||||
ld d, 0
|
||||
call MemorySet
|
||||
|
||||
|
||||
@@ -44,7 +44,8 @@ Intro:
|
||||
jr z, .setBGPalette
|
||||
|
||||
; fade bg palette
|
||||
ld b, 8
|
||||
FADE_DELAY = 8 ; frames
|
||||
ld b, FADE_DELAY
|
||||
.fadeDelay0
|
||||
HaltAndClearInterrupts
|
||||
dec b
|
||||
@@ -53,7 +54,7 @@ Intro:
|
||||
ld a, %11111100
|
||||
ldh [rBGP], a
|
||||
|
||||
ld b, 8
|
||||
ld b, FADE_DELAY
|
||||
.fadeDelay1
|
||||
HaltAndClearInterrupts
|
||||
dec b
|
||||
@@ -62,7 +63,7 @@ Intro:
|
||||
ld a, %11111000
|
||||
ldh [rBGP], a
|
||||
|
||||
ld b, 8
|
||||
ld b, FADE_DELAY
|
||||
.fadeDelay2
|
||||
HaltAndClearInterrupts
|
||||
dec b
|
||||
@@ -127,7 +128,7 @@ Intro:
|
||||
ld a, LCDCF_ON | LCDCF_BGON | LCDCF_BG9800
|
||||
ldh [rLCDC], a
|
||||
|
||||
; sound
|
||||
; sweep sound while transforming nintendo logo into game of life of it
|
||||
ld a, $77
|
||||
ldh [rNR10], a ; sweep
|
||||
ld a, (%00 << 6) + 0
|
||||
@@ -146,22 +147,23 @@ FREQUENCY = 146
|
||||
ld b, 20
|
||||
.loopX
|
||||
ld c, 2
|
||||
; 3 frame delay
|
||||
HaltAndClearInterrupts
|
||||
HaltAndClearInterrupts
|
||||
HaltAndClearInterrupts
|
||||
.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
|
||||
ld a, [hl]
|
||||
ld [de], a
|
||||
ld a, l
|
||||
add a, $20
|
||||
add a, SCRN_VX_B
|
||||
ld l, a
|
||||
ld a, e
|
||||
add a, $20
|
||||
add a, SCRN_VX_B
|
||||
ld e, a
|
||||
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 d
|
||||
dec c
|
||||
@@ -171,10 +173,10 @@ REPT 2
|
||||
ld a, [hl]
|
||||
ld [de], a
|
||||
ld a, l
|
||||
add a, $20
|
||||
add a, SCRN_VX_B
|
||||
ld l, a
|
||||
ld a, e
|
||||
add a, $20
|
||||
add a, SCRN_VX_B
|
||||
ld e, a
|
||||
ENDR
|
||||
; back to beginning (high byte)
|
||||
@@ -187,10 +189,10 @@ ENDR
|
||||
|
||||
; back to beginning + next column (low byte)
|
||||
ld a, l
|
||||
sub a, $3F
|
||||
sub a, SCRN_VX_B * 2 - 1
|
||||
ld l, a
|
||||
ld a, e
|
||||
sub a, $3F
|
||||
sub a, SCRN_VX_B * 2 - 1
|
||||
ld e, a
|
||||
|
||||
dec b
|
||||
|
||||
@@ -75,9 +75,9 @@ ENDR
|
||||
; copy default map into 20x18 automata buffer
|
||||
ld hl, DefaultMap
|
||||
ld de, Buffer0
|
||||
ld c, 18
|
||||
ld c, SCRN_Y_B
|
||||
.loopY
|
||||
ld b, 20
|
||||
ld b, SCRN_X_B
|
||||
|
||||
.loopX
|
||||
ld a, [hl+]
|
||||
@@ -90,7 +90,7 @@ ENDR
|
||||
jr z, .next
|
||||
|
||||
ld a, l
|
||||
add a, 32 - 20
|
||||
add a, SCRN_VX_B - SCRN_X_B
|
||||
ld l, a
|
||||
jr nc, .loopY
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
INCLUDE "hardware.inc"
|
||||
INCLUDE "utils.inc"
|
||||
INCLUDE "automata.inc"
|
||||
|
||||
RENDER_IN_HBL EQU 0
|
||||
|
||||
@@ -72,7 +71,7 @@ LCDStatInterruptHandler:
|
||||
|
||||
; go to next line
|
||||
ld a, e
|
||||
add a, SCRN_VX_B - TILE_WIDTH
|
||||
add a, SCRN_VX_B - SCRN_X_B
|
||||
ld e, a
|
||||
jr nc, .nocarry
|
||||
inc d
|
||||
@@ -83,7 +82,7 @@ LCDStatInterruptHandler:
|
||||
jr z, .finish
|
||||
|
||||
; reset tile counter
|
||||
ld c, TILE_WIDTH
|
||||
ld c, SCRN_X_B
|
||||
|
||||
jr .loop
|
||||
|
||||
@@ -137,9 +136,9 @@ StartRender:
|
||||
ld [Rendered + 1], a
|
||||
|
||||
; start rendering
|
||||
ld a, TILE_WIDTH
|
||||
ld a, SCRN_X_B
|
||||
ldh [TilesLeft], a
|
||||
ld a, TILE_HEIGHT
|
||||
ld a, SCRN_Y_B
|
||||
ldh [LinesLeft], a
|
||||
|
||||
; enable v-blank and lcd stat interrupt for h-blank
|
||||
|
||||
Binary file not shown.
24
Makefile
Normal file
24
Makefile
Normal 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
|
||||
Reference in New Issue
Block a user