do computations in work ram on a 32x32 grid (no display yet)
This commit is contained in:
163
Code/main.asm
163
Code/main.asm
@@ -69,17 +69,12 @@ Start:
|
|||||||
|
|
||||||
; load tiles
|
; load tiles
|
||||||
ld hl, _VRAM_BG_TILES
|
ld hl, _VRAM_BG_TILES
|
||||||
ld de, Tile0
|
ld de, Tiles
|
||||||
ld bc, 16
|
ld bc, 16
|
||||||
call MemoryCopy
|
call MemoryCopy
|
||||||
|
|
||||||
ld hl, _VRAM_BG_TILES + 16
|
ld hl, _VRAM_BG_TILES + 16
|
||||||
ld de, Tile1
|
ld de, Tiles + 16
|
||||||
ld bc, 16
|
|
||||||
call MemoryCopy
|
|
||||||
|
|
||||||
ld hl, _VRAM_BG_TILES + 32
|
|
||||||
ld de, Tile2
|
|
||||||
ld bc, 16
|
ld bc, 16
|
||||||
call MemoryCopy
|
call MemoryCopy
|
||||||
|
|
||||||
@@ -93,6 +88,12 @@ Start:
|
|||||||
ld de, DefaultMap
|
ld de, DefaultMap
|
||||||
ld bc, 32 * 32
|
ld bc, 32 * 32
|
||||||
call MemoryCopy
|
call MemoryCopy
|
||||||
|
|
||||||
|
; init buffer 0
|
||||||
|
ld hl, Buffer0
|
||||||
|
ld de, DefaultMap
|
||||||
|
ld bc, 32 * 32
|
||||||
|
call MemoryCopy
|
||||||
|
|
||||||
; display bg 9800
|
; display bg 9800
|
||||||
ld a, LCDCF_ON | LCDCF_BGON | LCDCF_BG9800
|
ld a, LCDCF_ON | LCDCF_BGON | LCDCF_BG9800
|
||||||
@@ -102,27 +103,22 @@ Start:
|
|||||||
ld a, STATF_MODE00
|
ld a, STATF_MODE00
|
||||||
ld [rSTAT], a
|
ld [rSTAT], a
|
||||||
|
|
||||||
; set old pointer to first tilemap
|
; set old pointer to buffer0
|
||||||
ld a, $98
|
ld a, HIGH(Buffer0)
|
||||||
ld [OldPointer + 1], a
|
ld [OldPointer + 1], a
|
||||||
|
|
||||||
; set new pointer to second tilemap
|
; set new pointer to buffer1
|
||||||
ld a, $9C
|
ld a, HIGH(Buffer1)
|
||||||
ld [NewPointer + 1], a
|
ld [NewPointer + 1], a
|
||||||
|
|
||||||
; set low bytes of pointers to 0
|
|
||||||
xor a
|
|
||||||
ld [NewPointer], a
|
|
||||||
ld [OldPointer], a
|
|
||||||
|
|
||||||
|
; set low byte of pointers to 0 (start of buffer is aligned)
|
||||||
|
xor a
|
||||||
|
ld [OldPointer + 0], a
|
||||||
|
ld [NewPointer + 0], a
|
||||||
|
|
||||||
.mainloop
|
.mainloop
|
||||||
|
|
||||||
; disable v-blank interrupt, enable lcd stat interrupt
|
.topleft
|
||||||
di
|
|
||||||
ld a, IEF_LCDC
|
|
||||||
ld [rIE], a
|
|
||||||
ei
|
|
||||||
|
|
||||||
; handle top left corner
|
; handle top left corner
|
||||||
ld bc, TopLeftCorner
|
ld bc, TopLeftCorner
|
||||||
call Conway
|
call Conway
|
||||||
@@ -134,7 +130,7 @@ Start:
|
|||||||
inc [hl]
|
inc [hl]
|
||||||
|
|
||||||
; handle all cells in top row except corners
|
; handle all cells in top row except corners
|
||||||
ld a, 18
|
ld a, 30
|
||||||
.top
|
.top
|
||||||
ld [XLoop], a
|
ld [XLoop], a
|
||||||
|
|
||||||
@@ -154,19 +150,18 @@ Start:
|
|||||||
jr nz, .top
|
jr nz, .top
|
||||||
|
|
||||||
; handle top right corner
|
; handle top right corner
|
||||||
|
.topright
|
||||||
ld bc, TopRightCorner
|
ld bc, TopRightCorner
|
||||||
call Conway
|
call Conway
|
||||||
|
|
||||||
; advance pointers to next row
|
; advance pointers to next row
|
||||||
ld a, [OldPointer]
|
ld hl, NewPointer
|
||||||
add a, 32 - 20 + 1
|
inc [hl]
|
||||||
ld [OldPointer], a
|
ld hl, OldPointer
|
||||||
; ld a, [NewPointer] ; unnecessary, both pointers are in sync and aligned the same
|
inc [hl]
|
||||||
; add a, 32 - 20 ; unnecessary, both pointers are in sync and aligned the same
|
|
||||||
ld [NewPointer], a
|
|
||||||
|
|
||||||
ld a, 16
|
ld a, 30
|
||||||
.columns
|
.leftcolumn
|
||||||
ld [YLoop], a
|
ld [YLoop], a
|
||||||
|
|
||||||
; handle first element in row
|
; handle first element in row
|
||||||
@@ -179,7 +174,7 @@ Start:
|
|||||||
ld hl, OldPointer
|
ld hl, OldPointer
|
||||||
inc [hl]
|
inc [hl]
|
||||||
|
|
||||||
ld a, 18
|
ld a, 30
|
||||||
.inner
|
.inner
|
||||||
ld [XLoop], a
|
ld [XLoop], a
|
||||||
|
|
||||||
@@ -199,15 +194,16 @@ Start:
|
|||||||
jr nz, .inner
|
jr nz, .inner
|
||||||
|
|
||||||
; handle last element in row
|
; handle last element in row
|
||||||
|
.rightcolumn
|
||||||
ld bc, RightColumn
|
ld bc, RightColumn
|
||||||
call Conway
|
call Conway
|
||||||
|
|
||||||
; advance to next row
|
; advance to next row
|
||||||
ld a, [NewPointer]
|
ld hl, NewPointer
|
||||||
add a, 32 - 20 + 1
|
inc [hl]
|
||||||
ld [NewPointer], a
|
ld hl, OldPointer
|
||||||
ld [OldPointer], a
|
inc [hl]
|
||||||
jr nc, .nocarry
|
jr nz, .nocarry
|
||||||
ld hl, NewPointer + 1
|
ld hl, NewPointer + 1
|
||||||
inc [hl]
|
inc [hl]
|
||||||
ld hl, OldPointer + 1
|
ld hl, OldPointer + 1
|
||||||
@@ -217,9 +213,10 @@ Start:
|
|||||||
; decrement y loop
|
; decrement y loop
|
||||||
ld a, [YLoop]
|
ld a, [YLoop]
|
||||||
dec a
|
dec a
|
||||||
jr nz, .columns
|
jr nz, .leftcolumn
|
||||||
|
|
||||||
; handle bottom left element
|
; handle bottom left element
|
||||||
|
.bottomleft
|
||||||
ld bc, BottomLeftCorner
|
ld bc, BottomLeftCorner
|
||||||
call Conway
|
call Conway
|
||||||
|
|
||||||
@@ -230,7 +227,7 @@ Start:
|
|||||||
inc [hl]
|
inc [hl]
|
||||||
|
|
||||||
; handle all cells in bottom row except corners
|
; handle all cells in bottom row except corners
|
||||||
ld a, 18
|
ld a, 30
|
||||||
.bottom
|
.bottom
|
||||||
ld [XLoop], a
|
ld [XLoop], a
|
||||||
|
|
||||||
@@ -250,16 +247,20 @@ Start:
|
|||||||
jr nz, .bottom
|
jr nz, .bottom
|
||||||
|
|
||||||
; handle last element
|
; handle last element
|
||||||
|
.bottomright
|
||||||
ld bc, BottomRightCorner
|
ld bc, BottomRightCorner
|
||||||
call Conway
|
call Conway
|
||||||
|
|
||||||
|
; wait for v-blank to swap pointers and render new buffer
|
||||||
|
halt
|
||||||
|
|
||||||
; swap buffers and reset pointers
|
; swap buffers and reset pointers
|
||||||
ld a, [NewPointer + 1]
|
ld a, [NewPointer + 1]
|
||||||
cp a, $9C
|
cp a, HIGH(Buffer1)
|
||||||
jr c, .newto9C00
|
jr c, .newToBuffer0
|
||||||
ld a, $98
|
ld a, HIGH(Buffer0)
|
||||||
ld [NewPointer + 1], a
|
ld [NewPointer + 1], a
|
||||||
ld a, $9C
|
ld a, HIGH(Buffer1)
|
||||||
ld [OldPointer + 1], a
|
ld [OldPointer + 1], a
|
||||||
|
|
||||||
; display bg 9C00
|
; display bg 9C00
|
||||||
@@ -267,10 +268,10 @@ Start:
|
|||||||
ld [rLCDC], a
|
ld [rLCDC], a
|
||||||
|
|
||||||
jr .resetlow
|
jr .resetlow
|
||||||
.newto9C00
|
.newToBuffer0
|
||||||
ld a, $9C
|
ld a, HIGH(Buffer1)
|
||||||
ld [NewPointer + 1], a
|
ld [NewPointer + 1], a
|
||||||
ld a, $98
|
ld a, HIGH(Buffer0)
|
||||||
ld [OldPointer + 1], a
|
ld [OldPointer + 1], a
|
||||||
|
|
||||||
; display bg 9800
|
; display bg 9800
|
||||||
@@ -282,18 +283,10 @@ Start:
|
|||||||
xor a
|
xor a
|
||||||
ld [NewPointer], a
|
ld [NewPointer], a
|
||||||
ld [OldPointer], a
|
ld [OldPointer], a
|
||||||
|
|
||||||
; enable v-blank interrupt, disable lcd stat interrupt
|
|
||||||
di
|
|
||||||
ld a, IEF_VBLANK
|
|
||||||
ld [rIE], a
|
|
||||||
ei
|
|
||||||
|
|
||||||
halt
|
|
||||||
|
|
||||||
jp .mainloop
|
jp .mainloop
|
||||||
|
|
||||||
SECTION "Table based conway's game of life step", ROM0
|
SECTION "Table based conway's game of life step for one cell", ROM0
|
||||||
; bc = pointer to neighbor offsets
|
; bc = pointer to neighbor offsets
|
||||||
; destroys all registers
|
; destroys all registers
|
||||||
Conway:
|
Conway:
|
||||||
@@ -328,7 +321,6 @@ Conway:
|
|||||||
add hl, de
|
add hl, de
|
||||||
|
|
||||||
; load neighbor
|
; load neighbor
|
||||||
halt
|
|
||||||
ld a, [hl]
|
ld a, [hl]
|
||||||
|
|
||||||
; check neighbor is alive
|
; check neighbor is alive
|
||||||
@@ -350,7 +342,6 @@ Conway:
|
|||||||
ld l, a
|
ld l, a
|
||||||
|
|
||||||
; load status
|
; load status
|
||||||
halt
|
|
||||||
ld a, [hl]
|
ld a, [hl]
|
||||||
|
|
||||||
; check if alive
|
; check if alive
|
||||||
@@ -403,29 +394,43 @@ Conway:
|
|||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
SECTION "Work", WRAM0
|
SECTION "Work", WRAM0[$C000]
|
||||||
|
Buffer0: ds 32 * 32
|
||||||
|
Buffer1: ds 32 * 32
|
||||||
OldPointer: ds 2
|
OldPointer: ds 2
|
||||||
NewPointer: ds 2
|
NewPointer: ds 2
|
||||||
Alive: ds 1
|
Alive: ds 1
|
||||||
XLoop: ds 1
|
XLoop: ds 1
|
||||||
YLoop: ds 1
|
YLoop: ds 1
|
||||||
|
Tile: ds 1
|
||||||
|
|
||||||
SECTION "Game Of Life Offset Tables", ROM0
|
SECTION "Game of Life neighboring cells offset tables", ROM0
|
||||||
; for a looping grid of 20x18 cells, with stride 32
|
; for a looping grid of 20x18 cells, with stride 32
|
||||||
TopLeftCorner: dw 1, 33, 32, 51, 19, 563, 544, 545, 0
|
;TopLeftCorner: dw 1, 33, 32, 51, 19, 563, 544, 545, 0
|
||||||
TopRightCorner: dw -19, 13, 32, 31, -1, 543, 544, 525, 0
|
;TopRightCorner: dw -19, 13, 32, 31, -1, 543, 544, 525, 0
|
||||||
BottomLeftCorner: dw 1, -543, -544, -525, 19, -13, -32, -31, 0
|
;BottomLeftCorner: dw 1, -543, -544, -525, 19, -13, -32, -31, 0
|
||||||
BottomRightCorner: dw -19, -563, -544, -545, -1, -33, -32, -51, 0
|
;BottomRightCorner: dw -19, -563, -544, -545, -1, -33, -32, -51, 0
|
||||||
TopRow: dw 1, 33, 32, 31, -1, 543, 544, 545, 0
|
;TopRow: dw 1, 33, 32, 31, -1, 543, 544, 545, 0
|
||||||
BottomRow: dw 1, -543, -544, -545, -1, -33, -32, -31, 0
|
;BottomRow: dw 1, -543, -544, -545, -1, -33, -32, -31, 0
|
||||||
LeftColumn: dw 1, 33, 32, 51, 19, -13, -32, -31, 0
|
;LeftColumn: dw 1, 33, 32, 51, 19, -13, -32, -31, 0
|
||||||
RightColumn: dw -19, 13, 32, 31, -1, -33, -32, -51, 0
|
;RightColumn: dw -19, 13, 32, 31, -1, -33, -32, -51, 0
|
||||||
Inner: dw 1, 33, 32, 31, -1, -33, -32, -31, 0
|
;Inner: dw 1, 33, 32, 31, -1, -33, -32, -31, 0
|
||||||
|
|
||||||
|
; for a looping grid of 32x32 cells
|
||||||
|
TopLeftCorner: dw 1, 33, 32, 63, 31, 1023, 992, 993, 0
|
||||||
|
TopRightCorner: dw -31, 1, 32, 31, -1, 991, 992, 961, 0
|
||||||
|
BottomLeftCorner: dw 1, -991, -992, -961, 31, -1, -32, -31, 0
|
||||||
|
BottomRightCorner: dw -31, -1023, -992, -993, -1, -33, -32, -63, 0
|
||||||
|
TopRow: dw 1, 33, 32, 31, -1, 991, 992, 993, 0
|
||||||
|
BottomRow: dw 1, -991, -992, -993, -1, -33, -32, -31, 0
|
||||||
|
LeftColumn: dw 1, 33, 32, 63, 31, -1, -32, -31, 0
|
||||||
|
RightColumn: dw -31, 1, 32, 31, -1, -33, -32, -63, 0
|
||||||
|
Inner: dw 1, 33, 32, 31, -1, -33, -32, -31, 0
|
||||||
|
|
||||||
SECTION "Graphics", ROM0
|
SECTION "Graphics", ROM0
|
||||||
Tile0: db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
|
Tiles:
|
||||||
Tile1: db $00, $FF, $00, $FF, $00, $FF, $00, $FF, $00, $FF, $00, $FF, $00, $FF, $00, $FF
|
INCBIN "Tiles.bin"
|
||||||
Tile2: db $FF, $00, $FF, $00, $FF, $00, $FF, $00, $FF, $00, $FF, $00, $FF, $00, $FF, $00
|
|
||||||
DefaultMap:
|
DefaultMap:
|
||||||
; pulsar period 3
|
; pulsar period 3
|
||||||
; 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
|
||||||
@@ -464,16 +469,16 @@ DefaultMap:
|
|||||||
; glider
|
; glider
|
||||||
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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