From 9790dc65026c22f26ea6e247c5506b88f36691a4 Mon Sep 17 00:00:00 2001 From: Astatin Date: Fri, 9 Aug 2024 21:19:36 +0900 Subject: Turn off screen during initialization to be compatible with sameboy --- Makefile | 6 ++++++ bunny.gbasm | 4 +++- definitions.gbasm | 1 + init.gbasm | 30 ++++++++++++++++++++++-------- main.gbasm | 8 ++++++-- tiles.gbasm | 2 +- 6 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index a0222e4..19d678f 100644 --- a/Makefile +++ b/Makefile @@ -9,5 +9,11 @@ build/main.rom: main.gbasm run: build/main.rom gb $< +sameboy: build/main.rom + sameboy build/main.rom + +gearboy: build/main.rom + gearboy build/main.rom + clean: rm -rf build diff --git a/bunny.gbasm b/bunny.gbasm index c6a06de..04d14a9 100644 --- a/bunny.gbasm +++ b/bunny.gbasm @@ -7,7 +7,7 @@ Initialize_Bunny: LD $reg_viewport_x, A LD A, $50 LD $mem_bunny_x_px, A - LD A, $50 + LD A, $48 LD $mem_bunny_y_px, A RET @@ -178,6 +178,7 @@ Display_Bunny: ; X position in $81, Y position in $80 LD A, B LD (HL+), A LD A, E + INC A LD (HL+), A LD A, D LD (HL+), A @@ -193,6 +194,7 @@ Display_Bunny: ; X position in $81, Y position in $80 LD (HL+), A LD A, E XOR $02 + INC A LD (HL+), A LD A, D LD (HL+), A diff --git a/definitions.gbasm b/definitions.gbasm index 8e9ea5b..fdefee8 100644 --- a/definitions.gbasm +++ b/definitions.gbasm @@ -1,5 +1,6 @@ .DEFINE reg_joypad ($00) .DEFINE reg_lcd_controller ($40) +.DEFINE reg_lcd_status ($41) .DEFINE reg_viewport_y ($42) .DEFINE reg_viewport_x ($43) .DEFINE reg_bg_palette ($47) diff --git a/init.gbasm b/init.gbasm index 20a5461..79d09f6 100644 --- a/init.gbasm +++ b/init.gbasm @@ -5,7 +5,7 @@ VBlank: .PADTO 0x0100 Start: - JP =Empty_VRAM + JP =Initialize_RAM .PADTO 0x0104 Nintendo_Logo: ; The Nintendo logo must be stored in bytes 0x104-133 @@ -18,10 +18,29 @@ Checksum: ; The bytes 0x134-0x14d need to add up to 0xe7 (= 0xff - 0x19) .DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 .DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$e7 +Initialize_RAM: +Empty_WRAM: + LD HL, $C000 + Empty_WRAM.loop: + XOR A + LD (HL+), a + LD a, $D0 + CP h + JR NZ, =Empty_WRAM.loop + +Wait_VBlank: + LD A, $reg_lcd_status + AND $03 + CP $01 + JR NZ, =Wait_VBlank + + ; LCDC + XOR A + LD $reg_lcd_controller, A + Empty_VRAM: ; (Clear screen) LD hl, $VRAM_start ; We set the HL register to the start of VRAM - -Empty_VRAM.loop: + Empty_VRAM.loop: XOR A LD (HL+), a ; We set the memory pointed to by HL to 0 and increase HL LD a, $a0 @@ -36,11 +55,6 @@ Empty_VRAM.loop: LD A, $e4 LD $reg_obj0_palette, A - ; LCDC - LD A, $reg_lcd_controller - OR $06 - LD $reg_lcd_controller, A - ; Interrupts LD A, $01 LD $reg_interrupt_enable, A diff --git a/main.gbasm b/main.gbasm index 7ef75fd..7f30a8e 100644 --- a/main.gbasm +++ b/main.gbasm @@ -3,9 +3,13 @@ Entrypoint: CALL =Load_Tile - CALL =Initialize_Bunny CALL =Load_Map - + CALL =Initialize_Bunny + + ; LCDC + LD A, $97 + LD $reg_lcd_controller, A + EI Wait_for_VRAM.loop: HALT diff --git a/tiles.gbasm b/tiles.gbasm index 4769e2a..bba72b9 100644 --- a/tiles.gbasm +++ b/tiles.gbasm @@ -62,7 +62,7 @@ memcpy: ; src = DE, dest = HL, n = BC RET Load_Tile: - LD HL, $8010 + LD HL, $8020 LD DE, =OBJ_Tile_Image_Data LD BC, $00c0 CALL =memcpy -- cgit v1.2.3-70-g09d2