Compare commits

...

10 Commits

Author SHA1 Message Date
d96588ec2d deleted old build batch file 2021-12-01 11:14:23 +01:00
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
0a2eef8336 use constants in edit code 2021-11-30 15:14:23 +01:00
fde5c95442 use automata and hardware constants in render 2021-11-29 17:20:29 +01:00
a2c8c40aaf added bug to todo 2021-11-29 17:04:50 +01:00
78432f66d9 added constants to automata code, more readable 2021-11-29 16:56:41 +01:00
0cff33d046 assume rgbds is in PATH; updated source to new version 2021-11-29 16:07:34 +01:00
5d68584179 added real name to license file 2021-11-29 16:00:34 +01:00
13 changed files with 76 additions and 58 deletions

2
.gitignore vendored
View File

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

View File

@@ -1,5 +1,7 @@
INCLUDE "hardware.inc" INCLUDE "hardware.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:
; ___ ___ ; ___ ___
@@ -9,11 +11,11 @@ INCLUDE "hardware.inc"
; bits 4, 5, 6 and 7 are not used ; bits 4, 5, 6 and 7 are not used
EXPORT Buffer0 EXPORT Buffer0
SECTION "Automata buffer 0", WRAM0, ALIGN[9] SECTION "Automata buffer 0", WRAM0, ALIGN[9]
Buffer0: ds 20 * 18 Buffer0: ds BUFFER_SIZE
EXPORT Buffer1 EXPORT Buffer1
SECTION "Automata buffer 1", WRAM0, ALIGN[9] SECTION "Automata buffer 1", WRAM0, ALIGN[9]
Buffer1: ds 20 * 18 Buffer1: ds BUFFER_SIZE
EXPORT New, Old, Progress EXPORT New, Old, Progress
SECTION "Automata data", HRAM SECTION "Automata data", HRAM
@@ -156,19 +158,19 @@ SECTION "Update Automata", ROM0
UpdateAutomata: UpdateAutomata:
.topleft .topleft
; handle top left corner ; handle top left corner
ConwayGroup 1, 21, 20, 39, 19, 359, 340, 341 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, 18 ld a, (SCRN_X_B - 2)
.top .top
ld [XLoop], a ld [XLoop], a
; handle top row cell ; handle top row cell
ConwayGroup 1, 21, 20, 19, -1, 339, 340, 341 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
@@ -181,18 +183,18 @@ UpdateAutomata:
; handle top right corner ; handle top right corner
.topright .topright
ConwayGroup -19, 1, 20, 19, -1, 339, 340, 321 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, 16 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, 21, 20, 39, 19, -1, -20, -19 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
@@ -203,7 +205,7 @@ UpdateAutomata:
ld [XLoop], a ld [XLoop], a
; handle element inside row ; handle element inside row
ConwayGroup 1, 21, 20, 19, -1, -21, -20, -19 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
@@ -222,7 +224,7 @@ UpdateAutomata:
; handle last element in row ; handle last element in row
.rightcolumn .rightcolumn
ConwayGroup -19, 1, 20, 19, -1, -21, -20, -39 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
@@ -235,19 +237,19 @@ UpdateAutomata:
; handle bottom left element ; handle bottom left element
.bottomleft .bottomleft
ConwayGroup 1, -339, -340, -321, 19, -1, -20, -19 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, 18 ld a, SCRN_X_B - 2
.bottom .bottom
ld [XLoop], a ld [XLoop], a
; handle top row cell ; handle top row cell
ConwayGroup 1, -339, -340, -341, -1, -21, -20, -19 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
@@ -260,7 +262,7 @@ UpdateAutomata:
; handle last element ; handle last element
.bottomright .bottomright
ConwayGroup -19, -359, -340, -341, -1, -21, -20, -39 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
@@ -306,4 +308,4 @@ InitAutomata:
ldh [Rendered], a ldh [Rendered], a
ldh [Video], a ldh [Video], a
ret ret

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
@@ -43,14 +43,13 @@ DefaultMap:
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
EXPORT BackgroundTiles, BackgroundTilesEnd
SECTION "Graphics", ROM0 SECTION "Graphics", ROM0
EXPORT BackgroundTiles, BackgroundTilesEnd
BackgroundTiles: BackgroundTiles:
INCBIN "BackgroundTiles.bin" INCBIN "BackgroundTiles.bin"
BackgroundTilesEnd: ds 0 BackgroundTilesEnd: ds 0
EXPORT SpriteTiles, SpriteTilesEnd EXPORT SpriteTiles, SpriteTilesEnd
SECTION "Graphics", ROM0
SpriteTiles: SpriteTiles:
INCBIN "SpriteTiles.bin" INCBIN "SpriteTiles.bin"
SpriteTilesEnd: ds 0 SpriteTilesEnd: ds 0

View File

@@ -16,9 +16,9 @@ SpriteDelay: ds 1
EXPORT InitEdit EXPORT InitEdit
SECTION "Init edit", ROM0 SECTION "Init edit", ROM0
InitEdit: InitEdit:
ld a, 20 ld a, SCRN_X_B
ldh [SelectX], a ldh [SelectX], a
ld a, 18 ld a, SCRN_Y_B
ldh [SelectY], a ldh [SelectY], a
xor a xor a
ldh [Down], a ldh [Down], a
@@ -210,7 +210,7 @@ ToggleCell:
ldh a, [Video + 1] ldh a, [Video + 1]
xor a, %100 xor a, %100
ld h, a ld h, a
MoveToCell 32 MoveToCell SCRN_VX_B
; toggle bit ; toggle bit
ld a, [hl] ld a, [hl]
@@ -222,7 +222,7 @@ ToggleCell:
ld l, a ld l, a
ldh a, [Old] ldh a, [Old]
ld h, a ld h, a
MoveToCell 20 MoveToCell SCRN_X_B
; toggle bit ; toggle bit
ld a, [hl] ld a, [hl]
@@ -271,7 +271,7 @@ Clear:
ld [Rendered + 1], a ld [Rendered + 1], a
; clear old buffer ; clear old buffer
ld bc, 20 * 18 ld bc, SCRN_X_B * SCRN_Y_B
ld d, 0 ld d, 0
call MemorySet call MemorySet

View File

@@ -25,7 +25,7 @@
; If all of these are already defined, don't do it again. ; If all of these are already defined, don't do it again.
IF !DEF(HARDWARE_INC) IF !DEF(HARDWARE_INC)
HARDWARE_INC SET 1 HARDWARE_INC = 1
rev_Check_hardware_inc : MACRO rev_Check_hardware_inc : MACRO
;NOTE: REVISION NUMBER CHANGES MUST BE ADDED ;NOTE: REVISION NUMBER CHANGES MUST BE ADDED

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

@@ -71,7 +71,7 @@ LCDStatInterruptHandler:
; go to next line ; go to next line
ld a, e ld a, e
add a, 32 - 20 add a, SCRN_VX_B - SCRN_X_B
ld e, a ld e, a
jr nc, .nocarry jr nc, .nocarry
inc d inc d
@@ -82,7 +82,7 @@ LCDStatInterruptHandler:
jr z, .finish jr z, .finish
; reset tile counter ; reset tile counter
ld c, 20 ld c, SCRN_X_B
jr .loop jr .loop
@@ -118,7 +118,7 @@ LCDStatInterruptHandler:
EXPORT InitRender EXPORT InitRender
SECTION "Init render", ROM0 SECTION "Init render", ROM0
InitRender: InitRender:
ld a, $9C ld a, HIGH(_SCRN1)
ldh [Video + 1], a ldh [Video + 1], a
xor a xor a
ldh [Video], a ldh [Video], a
@@ -136,9 +136,9 @@ StartRender:
ld [Rendered + 1], a ld [Rendered + 1], a
; start rendering ; start rendering
ld a, 20 ld a, SCRN_X_B
ldh [TilesLeft], a ldh [TilesLeft], a
ld a, 18 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.

View File

@@ -1,6 +1,6 @@
BSD 3-Clause License BSD 3-Clause License
Copyright (c) 2018, MsK` Copyright (c) 2018, Daniel Borges (MsK`)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

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

View File

@@ -1,10 +0,0 @@
..\..\Assembler\rgbasm %* -i Graphics\ -i Code\ -o Build\main.o Code\main.asm
..\..\Assembler\rgbasm %* -i Graphics\ -i Code\ -o Build\data.o Code\data.asm
..\..\Assembler\rgbasm %* -i Graphics\ -i Code\ -o Build\automata.o Code\automata.asm
..\..\Assembler\rgbasm %* -i Graphics\ -i Code\ -o Build\render.o Code\render.asm
..\..\Assembler\rgbasm %* -i Graphics\ -i Code\ -o Build\utils.o Code\utils.asm
..\..\Assembler\rgbasm %* -i Graphics\ -i Code\ -o Build\intro.o Code\intro.asm
..\..\Assembler\rgbasm %* -i Graphics\ -i Code\ -o Build\edit.o Code\edit.asm
..\..\Assembler\rgbasm %* -i Graphics\ -i Code\ -o Build\joypad.o Code\joypad.asm
..\..\Assembler\rgblink -n rom.sym -w -t -o rom.gb -d Build/main.o Build/data.o Build/automata.o Build/render.o Build/utils.o Build/intro.o Build/edit.o Build/joypad.o
..\..\Assembler\rgbfix -t "Game of Life" -v -p 0 rom.gb

View File

@@ -1,3 +1,4 @@
- music - music
- title screen - title screen
- cartridge! - cartridge!
- fix frame lag while editing