first commit

This commit is contained in:
Thorn Avery 2020-05-09 11:40:26 +12:00
commit f3fd560eae
25 changed files with 1840 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
build

16
Makefile Normal file
View File

@ -0,0 +1,16 @@
NAME=animation
ASSEMBLER=rgbasm
LINKER=rgblink
POSTPROC=rgbfix
SRC=./src
BUILD=./build
ENTRY=${SRC}/main.asm
ROM_OUTPUT=${BUILD}/${NAME}.gb
OBJECT_OUTPUT=${BUILD}/${NAME}.o
all : ${ENTRY}
${ASSEMBLER} -o ${OBJECT_OUTPUT} ${ENTRY} \
&& ${LINKER} -o ${ROM_OUTPUT} -n ${NAME}.sym ${OBJECT_OUTPUT} \
&& ${POSTPROC} -v -p 0 ${ROM_OUTPUT}

9
README.md Normal file
View File

@ -0,0 +1,9 @@
= tA's terribleAssembly =
just me messing about trying to learn gameboy assembly
== running ==
simply run `make` in the root directory to build the ROM
will appear as a `.gb` file in `./build`

54
animation.sym Normal file
View File

@ -0,0 +1,54 @@
; File generated by rgblink
00:0634 parecivo_tile_data
00:0234 Map
00:01F8 CheckBoundry
00:01E5 game_loop
00:0230 CheckBoundry.skipRender
00:021E CheckBoundry.swap
00:022C CheckBoundry.render
00:0150 Start
00:0017 dPlayerHeight
00:0016 dPlayerWidth
00:0018 dPlayerSpriteTiles
00:0008 CopyDMARoutine
00:0004 DMARoutine.wait
00:0000 DMARoutine
00:0008 DMARoutine.end
00:000F CopyDMARoutine.copy
00:0853 Read_Pad
00:084A MemCpy.copy
00:0883 Read_Pad.onenibble
00:086C Read_Pad.legalUpDown
00:0875 Read_Pad.legalLeftRight
00:084A MemCpy
00:0744 Wait_VBlank
00:0816 Clear_Map
00:0824 Load_Tiles
00:07D7 PC_Update
00:0750 Player_To_OAM
00:0747 Wait_VBlank.wait
00:07D1 Player_To_OAM.add4hl
00:0762 Player_To_OAM.finner
00:075E Player_To_OAM.fouter
00:0786 Player_To_OAM.sinner
00:077B Player_To_OAM.souter
00:07A5 Player_To_OAM.tloop1
00:07AA Player_To_OAM.tloop2
00:07C1 Player_To_OAM.lloop1
00:07C6 Player_To_OAM.lloop2
00:07E6 PC_Update.up
00:07F1 PC_Update.left
00:07FC PC_Update.right
00:0807 PC_Update.last
00:081D Clear_Map.loop
00:C005 rPlayerX
00:C006 rPlayerY
00:C004 ANS
00:C002 N
00:C000 X
00:C100 wShadowOAM
00:FF88 hVBlankFlag
00:FF89 hCurKeys
00:FF8A hNewKeys
00:FF80 hOAMDMA

129
ass/map.ass Normal file
View File

@ -0,0 +1,129 @@
; MAP.Z80
;
; Map Source File.
;
; Info:
; Section : Map
; Bank : 0
; Map size : 32 x 32
; Tile set : tiles.gbr
; Plane count : 1 plane (8 bits)
; Plane order : Tiles are continues
; Tile offset : 0
; Split data : No
;
; This file was generated by GBMB v1.8
MapWidth EQU 32
MapHeight EQU 32
MapBank EQU 0
Map_Size EQU (10*101)+4
SECTION "Map", ROM0
Map:
DB $03,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$03
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$03,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$03,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$03,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$03,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$03,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$03,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$03,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$03,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $03,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$03
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$03,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$03,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$03,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$03,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$03,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$03,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$03,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$03,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $03,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$03
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$03,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$03,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$03,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$03,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$03,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$03,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$03,$00
DB $00,$00,$04,$05,$00,$00,$00,$03,$03,$00
DB $00,$00,$00,$00,$00,$00,$00,$03,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $03,$03,$00,$00,$06,$07,$00,$00,$03,$03
DB $03,$03,$00,$00,$00,$01,$00,$00,$03,$03
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$03,$03,$03,$00,$08,$09,$00,$03
DB $03,$03,$03,$03,$03,$00,$00,$02,$00,$03
DB $03,$03,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$03,$03,$03,$03,$03,$03
DB $03,$03,$03,$03,$03,$03,$03,$03,$03,$03
DB $03,$03,$03,$03,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00
; End of MAP.Z80

BIN
ass/map.gbm Normal file

Binary file not shown.

27
ass/parecivo.ass Normal file
View File

@ -0,0 +1,27 @@
;-----------------------------------------
; Animation Test: .i pa .e re .e ci .e vo
;-----------------------------------------
SECTION "parecivoTiles", ROM0
parecivo_tile_data_size EQU $0110
parecivo_tile_count EQU $11
parecivo_tile_data::
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$7F,$7F,$40,$40,$4E,$4E,$51,$51,$51,$51,$51,$51,$5E,$5E
DB $00,$00,$FE,$FE,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
DB $00,$00,$7F,$7F,$40,$40,$57,$57,$48,$48,$48,$48,$48,$48,$48,$48
DB $00,$00,$FE,$FE,$02,$02,$02,$02,$82,$82,$82,$82,$02,$02,$E2,$E2
DB $00,$00,$7F,$7F,$40,$40,$4F,$4F,$50,$50,$50,$50,$50,$50,$50,$50
DB $00,$00,$FE,$FE,$02,$02,$02,$02,$92,$92,$82,$82,$12,$12,$12,$12
DB $00,$00,$7F,$7F,$40,$40,$50,$50,$50,$50,$48,$48,$48,$48,$45,$45
DB $00,$00,$FE,$FE,$02,$02,$42,$42,$42,$42,$82,$82,$82,$82,$02,$02
DB $50,$50,$51,$51,$51,$51,$51,$51,$50,$50,$40,$40,$7F,$7F,$00,$00
DB $E2,$E2,$12,$12,$12,$12,$12,$12,$EA,$EA,$02,$02,$FE,$FE,$00,$00
DB $49,$49,$49,$49,$49,$49,$49,$49,$48,$48,$40,$40,$7F,$7F,$00,$00
DB $12,$12,$12,$12,$E2,$E2,$02,$02,$F2,$F2,$02,$02,$FE,$FE,$00,$00
DB $50,$50,$50,$50,$50,$50,$50,$50,$4F,$4F,$40,$40,$7F,$7F,$00,$00
DB $12,$12,$12,$12,$92,$92,$92,$92,$3A,$3A,$02,$02,$FE,$FE,$00,$00
DB $45,$45,$42,$42,$40,$40,$40,$40,$40,$40,$40,$40,$7F,$7F,$00,$00
DB $32,$32,$4A,$4A,$4A,$4A,$4A,$4A,$32,$32,$02,$02,$FE,$FE,$00,$00

BIN
ass/parecivo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 B

25
ass/tiles.ass Normal file
View File

@ -0,0 +1,25 @@
SECTION "Tiles", ROM0
Tiles_Size EQU 8*20
Tiles:
DB $00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00
DB $3C,$3C,$42,$42,$81,$81,$A5,$A5
DB $81,$81,$99,$99,$42,$42,$3C,$3C
DB $18,$18,$FF,$FF,$99,$99,$99,$99
DB $BD,$BD,$24,$24,$24,$24,$24,$24
DB $00,$FF,$7E,$81,$66,$A5,$42,$81
DB $42,$81,$66,$A5,$7E,$81,$00,$FF
DB $00,$00,$3E,$3E,$51,$5F,$0C,$0B
DB $06,$05,$1F,$1C,$37,$2C,$7F,$7F
DB $00,$00,$00,$00,$00,$00,$80,$80
DB $40,$C0,$38,$F8,$34,$EC,$F8,$F8
DB $0F,$00,$0F,$02,$0F,$00,$05,$03
DB $02,$01,$06,$01,$0F,$00,$0F,$10
DB $00,$E0,$80,$E0,$00,$E0,$80,$C0
DB $C0,$C0,$60,$E0,$30,$F0,$90,$70
DB $2F,$10,$0F,$20,$06,$01,$07,$00
DB $04,$02,$04,$02,$0C,$02,$18,$06
DB $90,$68,$08,$E0,$00,$C0,$00,$C0
DB $80,$40,$80,$40,$80,$60,$C0,$30

BIN
ass/tiles.gbr Normal file

Binary file not shown.

840
inc/hardware.inc Normal file
View File

@ -0,0 +1,840 @@
;*
;* Gameboy Hardware definitions
;*
;* Based on Jones' hardware.inc
;* And based on Carsten Sorensen's ideas.
;*
;* Rev 1.1 - 15-Jul-97 : Added define check
;* Rev 1.2 - 18-Jul-97 : Added revision check macro
;* Rev 1.3 - 19-Jul-97 : Modified for RGBASM V1.05
;* Rev 1.4 - 27-Jul-97 : Modified for new subroutine prefixes
;* Rev 1.5 - 15-Aug-97 : Added _HRAM, PAD, CART defines
;* : and Nintendo Logo
;* Rev 1.6 - 30-Nov-97 : Added rDIV, rTIMA, rTMA, & rTAC
;* Rev 1.7 - 31-Jan-98 : Added _SCRN0, _SCRN1
;* Rev 1.8 - 15-Feb-98 : Added rSB, rSC
;* Rev 1.9 - 16-Feb-98 : Converted I/O registers to $FFXX format
;* Rev 2.0 - : Added GBC registers
;* Rev 2.1 - : Added MBC5 & cart RAM enable/disable defines
;* Rev 2.2 - : Fixed NR42,NR43, & NR44 equates
;* Rev 2.3 - : Fixed incorrect _HRAM equate
;* Rev 2.4 - 27-Apr-13 : Added some cart defines (AntonioND)
;* Rev 2.5 - 03-May-15 : Fixed format (AntonioND)
;* Rev 2.6 - 09-Apr-16 : Added GBC OAM and cart defines (AntonioND)
;* Rev 2.7 - 19-Jan-19 : Added rPCMXX (ISSOtm)
;* Rev 2.8 - 03-Feb-19 : Added audio registers flags (Álvaro Cuesta)
; If all of these are already defined, don't do it again.
IF !DEF(HARDWARE_INC)
HARDWARE_INC SET 1
rev_Check_hardware_inc : MACRO
;NOTE: REVISION NUMBER CHANGES MUST BE ADDED
;TO SECOND PARAMETER IN FOLLOWING LINE.
IF \1 > 2.8 ;PUT REVISION NUMBER HERE
WARN "Version \1 or later of 'hardware.inc' is required."
ENDC
ENDM
_HW EQU $FF00
_VRAM EQU $8000 ; $8000->$9FFF
_BGTILES EQU $9000
_SCRN0 EQU $9800 ; $9800->$9BFF
_SCRN0_END EQU $9BFF
_SCRN1 EQU $9C00 ; $9C00->$9FFF
_SRAM EQU $A000 ; $A000->$BFFF
_RAM EQU $C000 ; $C000->$DFFF
_OAMRAM EQU $FE00 ; $FE00->$FE9F
_AUD3WAVERAM EQU $FF30 ; $FF30->$FF3F
_HRAM EQU $FF80 ; $FF80->$FFFE
; *** MBC5 Equates ***
rRAMG EQU $0000 ; $0000->$1fff
rROMB0 EQU $2000 ; $2000->$2fff
rROMB1 EQU $3000 ; $3000->$3fff - If more than 256 ROM banks are present.
rRAMB EQU $4000 ; $4000->$5fff - Bit 3 enables rumble (if present)
; --
; -- OAM flags
; --
OAMF_PRI EQU %10000000 ; Priority
OAMF_YFLIP EQU %01000000 ; Y flip
OAMF_XFLIP EQU %00100000 ; X flip
OAMF_PAL0 EQU %00000000 ; Palette number; 0,1 (DMG)
OAMF_PAL1 EQU %00010000 ; Palette number; 0,1 (DMG)
OAMF_BANK0 EQU %00000000 ; Bank number; 0,1 (GBC)
OAMF_BANK1 EQU %00001000 ; Bank number; 0,1 (GBC)
OAMF_PALMASK EQU %00000111 ; Palette (GBC)
OAMB_PRI EQU 7 ; Priority
OAMB_YFLIP EQU 6 ; Y flip
OAMB_XFLIP EQU 5 ; X flip
OAMB_PAL1 EQU 4 ; Palette number; 0,1 (DMG)
OAMB_BANK1 EQU 3 ; Bank number; 0,1 (GBC)
;***************************************************************************
;*
;* Custom registers
;*
;***************************************************************************
; --
; -- P1 ($FF00)
; -- Register for reading joy pad info. (R/W)
; --
rP1 EQU $FF00
P1F_5 EQU %00100000 ; P15 out port
P1F_4 EQU %00010000 ; P14 out port
P1F_3 EQU %00001000 ; P13 in port
P1F_2 EQU %00000100 ; P12 in port
P1F_1 EQU %00000010 ; P11 in port
P1F_0 EQU %00000001 ; P10 in port
; --
; -- SB ($FF01)
; -- Serial Transfer Data (R/W)
; --
rSB EQU $FF01
; --
; -- SC ($FF02)
; -- Serial I/O Control (R/W)
; --
rSC EQU $FF02
; --
; -- DIV ($FF04)
; -- Divider register (R/W)
; --
rDIV EQU $FF04
; --
; -- TIMA ($FF05)
; -- Timer counter (R/W)
; --
rTIMA EQU $FF05
; --
; -- TMA ($FF06)
; -- Timer modulo (R/W)
; --
rTMA EQU $FF06
; --
; -- TAC ($FF07)
; -- Timer control (R/W)
; --
rTAC EQU $FF07
TACF_START EQU %00000100
TACF_STOP EQU %00000000
TACF_4KHZ EQU %00000000
TACF_16KHZ EQU %00000011
TACF_65KHZ EQU %00000010
TACF_262KHZ EQU %00000001
; --
; -- IF ($FF0F)
; -- Interrupt Flag (R/W)
; --
rIF EQU $FF0F
; --
; -- LCDC ($FF40)
; -- LCD Control (R/W)
; --
rLCDC EQU $FF40
LCDCF_OFF EQU %00000000 ; LCD Control Operation
LCDCF_ON EQU %10000000 ; LCD Control Operation
LCDCF_WIN9800 EQU %00000000 ; Window Tile Map Display Select
LCDCF_WIN9C00 EQU %01000000 ; Window Tile Map Display Select
LCDCF_WINOFF EQU %00000000 ; Window Display
LCDCF_WINON EQU %00100000 ; Window Display
LCDCF_BG8800 EQU %00000000 ; BG & Window Tile Data Select
LCDCF_BG8000 EQU %00010000 ; BG & Window Tile Data Select
LCDCF_BG9800 EQU %00000000 ; BG Tile Map Display Select
LCDCF_BG9C00 EQU %00001000 ; BG Tile Map Display Select
LCDCF_OBJ8 EQU %00000000 ; OBJ Construction
LCDCF_OBJ16 EQU %00000100 ; OBJ Construction
LCDCF_OBJOFF EQU %00000000 ; OBJ Display
LCDCF_OBJON EQU %00000010 ; OBJ Display
LCDCF_BGOFF EQU %00000000 ; BG Display
LCDCF_BGON EQU %00000001 ; BG Display
; "Window Character Data Select" follows BG
; --
; -- STAT ($FF41)
; -- LCDC Status (R/W)
; --
rSTAT EQU $FF41
STATF_LYC EQU %01000000 ; LYCEQULY Coincidence (Selectable)
STATF_MODE10 EQU %00100000 ; Mode 10
STATF_MODE01 EQU %00010000 ; Mode 01 (V-Blank)
STATF_MODE00 EQU %00001000 ; Mode 00 (H-Blank)
STATF_LYCF EQU %00000100 ; Coincidence Flag
STATF_HB EQU %00000000 ; H-Blank
STATF_VB EQU %00000001 ; V-Blank
STATF_OAM EQU %00000010 ; OAM-RAM is used by system
STATF_LCD EQU %00000011 ; Both OAM and VRAM used by system
STATF_BUSY EQU %00000010 ; When set, VRAM access is unsafe
; --
; -- SCY ($FF42)
; -- Scroll Y (R/W)
; --
rSCY EQU $FF42
; --
; -- SCY ($FF43)
; -- Scroll X (R/W)
; --
rSCX EQU $FF43
; --
; -- LY ($FF44)
; -- LCDC Y-Coordinate (R)
; --
; -- Values range from 0->153. 144->153 is the VBlank period.
; --
rLY EQU $FF44
; --
; -- LYC ($FF45)
; -- LY Compare (R/W)
; --
; -- When LYEQUEQULYC, STATF_LYCF will be set in STAT
; --
rLYC EQU $FF45
; --
; -- DMA ($FF46)
; -- DMA Transfer and Start Address (W)
; --
rDMA EQU $FF46
; --
; -- BGP ($FF47)
; -- BG Palette Data (W)
; --
; -- Bit 7-6 - Intensity for %11
; -- Bit 5-4 - Intensity for %10
; -- Bit 3-2 - Intensity for %01
; -- Bit 1-0 - Intensity for %00
; --
rBGP EQU $FF47
; --
; -- OBP0 ($FF48)
; -- Object Palette 0 Data (W)
; --
; -- See BGP for info
; --
rOBP0 EQU $FF48
; --
; -- OBP1 ($FF49)
; -- Object Palette 1 Data (W)
; --
; -- See BGP for info
; --
rOBP1 EQU $FF49
; --
; -- WY ($FF4A)
; -- Window Y Position (R/W)
; --
; -- 0 <EQU WY <EQU 143
; --
rWY EQU $FF4A
; --
; -- WX ($FF4B)
; -- Window X Position (R/W)
; --
; -- 7 <EQU WX <EQU 166
; --
rWX EQU $FF4B
; --
; -- KEY 1 ($FF4D)
; -- Select CPU Speed (R/W)
; --
rKEY1 EQU $FF4D
; --
; -- VBK ($FF4F)
; -- Select Video RAM Bank (R/W)
; --
rVBK EQU $FF4F
; --
; -- HDMA1 ($FF51)
; -- Horizontal Blanking, General Purpose DMA (W)
; --
rHDMA1 EQU $FF51
; --
; -- HDMA2 ($FF52)
; -- Horizontal Blanking, General Purpose DMA (W)
; --
rHDMA2 EQU $FF52
; --
; -- HDMA3 ($FF53)
; -- Horizontal Blanking, General Purpose DMA (W)
; --
rHDMA3 EQU $FF53
; --
; -- HDMA4 ($FF54)
; -- Horizontal Blanking, General Purpose DMA (W)
; --
rHDMA4 EQU $FF54
; --
; -- HDMA5 ($FF55)
; -- Horizontal Blanking, General Purpose DMA (R/W)
; --
rHDMA5 EQU $FF55
; --
; -- RP ($FF56)
; -- Infrared Communications Port (R/W)
; --
rRP EQU $FF56
; --
; -- BCPS ($FF68)
; -- Background Color Palette Specification (R/W)
; --
rBCPS EQU $FF68
; --
; -- BCPD ($FF69)
; -- Background Color Palette Data (R/W)
; --
rBCPD EQU $FF69
; --
; -- BCPS ($FF6A)
; -- Object Color Palette Specification (R/W)
; --
rOCPS EQU $FF6A
; --
; -- BCPD ($FF6B)
; -- Object Color Palette Data (R/W)
; --
rOCPD EQU $FF6B
; --
; -- SVBK ($FF4F)
; -- Select Main RAM Bank (R/W)
; --
rSVBK EQU $FF70
; --
; -- IE ($FFFF)
; -- Interrupt Enable (R/W)
; --
rIE EQU $FFFF
IEF_HILO EQU %00010000 ; Transition from High to Low of Pin number P10-P13
IEF_SERIAL EQU %00001000 ; Serial I/O transfer end
IEF_TIMER EQU %00000100 ; Timer Overflow
IEF_LCDC EQU %00000010 ; LCDC (see STAT)
IEF_VBLANK EQU %00000001 ; V-Blank
;***************************************************************************
;*
;* Sound control registers
;*
;***************************************************************************
; --
; -- AUDVOL/NR50 ($FF24)
; -- Channel control / ON-OFF / Volume (R/W)
; --
; -- Bit 7 - Vin->SO2 ON/OFF (Vin??)
; -- Bit 6-4 - SO2 output level (volume) (# 0-7)
; -- Bit 3 - Vin->SO1 ON/OFF (Vin??)
; -- Bit 2-0 - SO1 output level (volume) (# 0-7)
; --
rNR50 EQU $FF24
rAUDVOL EQU rNR50
AUDVOL_VIN_LEFT EQU %10000000 ; SO2
AUDVOL_VIN_RIGHT EQU %00001000 ; SO1
; --
; -- AUDTERM/NR51 ($FF25)
; -- Selection of Sound output terminal (R/W)
; --
; -- Bit 7 - Output sound 4 to SO2 terminal
; -- Bit 6 - Output sound 3 to SO2 terminal
; -- Bit 5 - Output sound 2 to SO2 terminal
; -- Bit 4 - Output sound 1 to SO2 terminal
; -- Bit 3 - Output sound 4 to SO1 terminal
; -- Bit 2 - Output sound 3 to SO1 terminal
; -- Bit 1 - Output sound 2 to SO1 terminal
; -- Bit 0 - Output sound 0 to SO1 terminal
; --
rNR51 EQU $FF25
rAUDTERM EQU rNR51
; SO2
AUDTERM_4_LEFT EQU %10000000
AUDTERM_3_LEFT EQU %01000000
AUDTERM_2_LEFT EQU %00100000
AUDTERM_1_LEFT EQU %00010000
; SO1
AUDTERM_4_RIGHT EQU %00001000
AUDTERM_3_RIGHT EQU %00000100
AUDTERM_2_RIGHT EQU %00000010
AUDTERM_1_RIGHT EQU %00000001
; --
; -- AUDENA/NR52 ($FF26)
; -- Sound on/off (R/W)
; --
; -- Bit 7 - All sound on/off (sets all audio regs to 0!)
; -- Bit 3 - Sound 4 ON flag (doesn't work!)
; -- Bit 2 - Sound 3 ON flag (doesn't work!)
; -- Bit 1 - Sound 2 ON flag (doesn't work!)
; -- Bit 0 - Sound 1 ON flag (doesn't work!)
; --
rNR52 EQU $FF26
rAUDENA EQU rNR52
AUDENA_ON EQU %10000000
AUDENA_OFF EQU %00000000 ; sets all audio regs to 0!
;***************************************************************************
;*
;* SoundChannel #1 registers
;*
;***************************************************************************
; --
; -- AUD1SWEEP/NR10 ($FF10)
; -- Sweep register (R/W)
; --
; -- Bit 6-4 - Sweep Time
; -- Bit 3 - Sweep Increase/Decrease
; -- 0: Addition (frequency increases???)
; -- 1: Subtraction (frequency increases???)
; -- Bit 2-0 - Number of sweep shift (# 0-7)
; -- Sweep Time: (n*7.8ms)
; --
rNR10 EQU $FF10
rAUD1SWEEP EQU rNR10
AUD1SWEEP_UP EQU %00000000
AUD1SWEEP_DOWN EQU %00001000
; --
; -- AUD1LEN/NR11 ($FF11)
; -- Sound length/Wave pattern duty (R/W)
; --
; -- Bit 7-6 - Wave Pattern Duty (00:12.5% 01:25% 10:50% 11:75%)
; -- Bit 5-0 - Sound length data (# 0-63)
; --
rNR11 EQU $FF11
rAUD1LEN EQU rNR11
; --
; -- AUD1ENV/NR12 ($FF12)
; -- Envelope (R/W)
; --
; -- Bit 7-4 - Initial value of envelope
; -- Bit 3 - Envelope UP/DOWN
; -- 0: Decrease
; -- 1: Range of increase
; -- Bit 2-0 - Number of envelope sweep (# 0-7)
; --
rNR12 EQU $FF12
rAUD1ENV EQU rNR12
; --
; -- AUD1LOW/NR13 ($FF13)
; -- Frequency lo (W)
; --
rNR13 EQU $FF13
rAUD1LOW EQU rNR13
; --
; -- AUD1HIGH/NR14 ($FF14)
; -- Frequency hi (W)
; --
; -- Bit 7 - Initial (when set, sound restarts)
; -- Bit 6 - Counter/consecutive selection
; -- Bit 2-0 - Frequency's higher 3 bits
; --
rNR14 EQU $FF14
rAUD1HIGH EQU rNR14
;***************************************************************************
;*
;* SoundChannel #2 registers
;*
;***************************************************************************
; --
; -- AUD2LEN/NR21 ($FF16)
; -- Sound Length; Wave Pattern Duty (R/W)
; --
; -- see AUD1LEN for info
; --
rNR21 EQU $FF16
rAUD2LEN EQU rNR21
; --
; -- AUD2ENV/NR22 ($FF17)
; -- Envelope (R/W)
; --
; -- see AUD1ENV for info
; --
rNR22 EQU $FF17
rAUD2ENV EQU rNR22
; --
; -- AUD2LOW/NR23 ($FF18)
; -- Frequency lo (W)
; --
rNR23 EQU $FF18
rAUD2LOW EQU rNR23
; --
; -- AUD2HIGH/NR24 ($FF19)
; -- Frequency hi (W)
; --
; -- see AUD1HIGH for info
; --
rNR24 EQU $FF19
rAUD2HIGH EQU rNR24
;***************************************************************************
;*
;* SoundChannel #3 registers
;*
;***************************************************************************
; --
; -- AUD3ENA/NR30 ($FF1A)
; -- Sound on/off (R/W)
; --
; -- Bit 7 - Sound ON/OFF (1EQUON,0EQUOFF)
; --
rNR30 EQU $FF1A
rAUD3ENA EQU rNR30
; --
; -- AUD3LEN/NR31 ($FF1B)
; -- Sound length (R/W)
; --
; -- Bit 7-0 - Sound length
; --
rNR31 EQU $FF1B
rAUD3LEN EQU rNR31
; --
; -- AUD3LEVEL/NR32 ($FF1C)
; -- Select output level
; --
; -- Bit 6-5 - Select output level
; -- 00: 0/1 (mute)
; -- 01: 1/1
; -- 10: 1/2
; -- 11: 1/4
; --
rNR32 EQU $FF1C
rAUD3LEVEL EQU rNR32
; --
; -- AUD3LOW/NR33 ($FF1D)
; -- Frequency lo (W)
; --
; -- see AUD1LOW for info
; --
rNR33 EQU $FF1D
rAUD3LOW EQU rNR33
; --
; -- AUD3HIGH/NR34 ($FF1E)
; -- Frequency hi (W)
; --
; -- see AUD1HIGH for info
; --
rNR34 EQU $FF1E
rAUD3HIGH EQU rNR34
; --
; -- AUD4LEN/NR41 ($FF20)
; -- Sound length (R/W)
; --
; -- Bit 5-0 - Sound length data (# 0-63)
; --
rNR41 EQU $FF20
rAUD4LEN EQU rNR41
; --
; -- AUD4ENV/NR42 ($FF21)
; -- Envelope (R/W)
; --
; -- see AUD1ENV for info
; --
rNR42 EQU $FF21
rAUD4ENV EQU rNR42
; --
; -- AUD4POLY/NR43 ($FF22)
; -- Polynomial counter (R/W)
; --
; -- Bit 7-4 - Selection of the shift clock frequency of the (scf)
; -- polynomial counter (0000-1101)
; -- freqEQUdrf*1/2^scf (not sure)
; -- Bit 3 - Selection of the polynomial counter's step
; -- 0: 15 steps
; -- 1: 7 steps
; -- Bit 2-0 - Selection of the dividing ratio of frequencies (drf)
; -- 000: f/4 001: f/8 010: f/16 011: f/24
; -- 100: f/32 101: f/40 110: f/48 111: f/56 (fEQU4.194304 Mhz)
; --
rNR43 EQU $FF22
rAUD4POLY EQU rNR43
; --
; -- AUD4GO/NR44 ($FF23)
; -- (has wrong name and value (ff30) in Dr.Pan's doc!)
; --
; -- Bit 7 - Inital
; -- Bit 6 - Counter/consecutive selection
; --
rNR44 EQU $FF23
rAUD4GO EQU rNR44 ; silly name!
; --
; -- PCM12 ($FF76)
; -- Sound channel 1&2 PCM amplitude (R)
; --
; -- Bit 7-4 - Copy of sound channel 2's PCM amplitude
; -- Bit 3-0 - Copy of sound channel 1's PCM amplitude
; --
rPCM12 EQU $FF76
; --
; -- PCM34 ($FF77)
; -- Sound channel 3&4 PCM amplitude (R)
; --
; -- Bit 7-4 - Copy of sound channel 4's PCM amplitude
; -- Bit 3-0 - Copy of sound channel 3's PCM amplitude
; --
rPCM34 EQU $FF77
;***************************************************************************
;*
;* Flags common to multiple sound channels
;*
;***************************************************************************
; --
; -- Square wave duty cycle
; --
; -- Can be used with AUD1LEN and AUD2LEN
; -- See AUD1LEN for more info
; --
AUDLEN_DUTY_12_5 EQU %00000000 ; 12.5%
AUDLEN_DUTY_25 EQU %01000000 ; 25%
AUDLEN_DUTY_50 EQU %10000000 ; 50%
AUDLEN_DUTY_75 EQU %11000000 ; 75%
; --
; -- Audio envelope flags
; --
; -- Can be used with AUD1ENV, AUD2ENV, AUD4ENV
; -- See AUD1ENV for more info
; --
AUDENV_UP EQU %00001000
AUDENV_DOWN EQU %00000000
; --
; -- Audio trigger flags
; --
; -- Can be used with AUD1HIGH, AUD2HIGH, AUD3HIGH
; -- See AUD1HIGH for more info
; --
AUDHIGH_RESTART EQU %10000000
AUDHIGH_LENGTH_ON EQU %01000000
AUDHIGH_LENGTH_OFF EQU %00000000
;***************************************************************************
;*
;* Cart related
;*
;***************************************************************************
CART_COMPATIBLE_DMG EQU $00
CART_COMPATIBLE_DMG_GBC EQU $80
CART_COMPATIBLE_GBC EQU $C0
CART_ROM EQU $00
CART_ROM_MBC1 EQU $01
CART_ROM_MBC1_RAM EQU $02
CART_ROM_MBC1_RAM_BAT EQU $03
CART_ROM_MBC2 EQU $05
CART_ROM_MBC2_BAT EQU $06
CART_ROM_RAM EQU $08
CART_ROM_RAM_BAT EQU $09
CART_ROM_MBC3_BAT_RTC EQU $0F
CART_ROM_MBC3_RAM_BAT_RTC EQU $10
CART_ROM_MBC3 EQU $11
CART_ROM_MBC3_RAM EQU $12
CART_ROM_MBC3_RAM_BAT EQU $13
CART_ROM_MBC5 EQU $19
CART_ROM_MBC5_BAT EQU $1A
CART_ROM_MBC5_RAM_BAT EQU $1B
CART_ROM_MBC5_RUMBLE EQU $1C
CART_ROM_MBC5_RAM_RUMBLE EQU $1D
CART_ROM_MBC5_RAM_BAT_RUMBLE EQU $1E
CART_ROM_MBC7_RAM_BAT_GYRO EQU $22
CART_ROM_POCKET_CAMERA EQU $FC
CART_ROM_256K EQU 0 ; 2 banks
CART_ROM_512K EQU 1 ; 4 banks
CART_ROM_1M EQU 2 ; 8 banks
CART_ROM_2M EQU 3 ; 16 banks
CART_ROM_4M EQU 4 ; 32 banks
CART_ROM_8M EQU 5 ; 64 banks
CART_ROM_16M EQU 6 ; 128 banks
CART_ROM_32M EQU 7 ; 256 banks
CART_ROM_64M EQU 8 ; 512 banks
CART_RAM_NONE EQU 0
CART_RAM_16K EQU 1 ; 1 incomplete bank
CART_RAM_64K EQU 2 ; 1 bank
CART_RAM_256K EQU 3 ; 4 banks
CART_RAM_1M EQU 4 ; 16 banks
CART_RAM_ENABLE EQU $0A
CART_RAM_DISABLE EQU $00
;***************************************************************************
;*
;* Keypad related
;*
;***************************************************************************
PADF_DOWN EQU $80
PADF_UP EQU $40
PADF_LEFT EQU $20
PADF_RIGHT EQU $10
PADF_START EQU $08
PADF_SELECT EQU $04
PADF_B EQU $02
PADF_A EQU $01
PADB_DOWN EQU $7
PADB_UP EQU $6
PADB_LEFT EQU $5
PADB_RIGHT EQU $4
PADB_START EQU $3
PADB_SELECT EQU $2
PADB_B EQU $1
PADB_A EQU $0
;***************************************************************************
;*
;* Screen related
;*
;***************************************************************************
SCRN_X EQU 160 ; Width of screen in pixels
SCRN_Y EQU 144 ; Height of screen in pixels
SCRN_X_B EQU 20 ; Width of screen in bytes
SCRN_Y_B EQU 18 ; Height of screen in bytes
SCRN_VX EQU 256 ; Virtual width of screen in pixels
SCRN_VY EQU 256 ; Virtual height of screen in pixels
SCRN_VX_B EQU 32 ; Virtual width of screen in bytes
SCRN_VY_B EQU 32 ; Virtual height of screen in bytes
;*
;* Nintendo scrolling logo
;* (Code won't work on a real GameBoy)
;* (if next lines are altered.)
NINTENDO_LOGO : MACRO
DB $CE,$ED,$66,$66,$CC,$0D,$00,$0B,$03,$73,$00,$83,$00,$0C,$00,$0D
DB $00,$08,$11,$1F,$88,$89,$00,$0E,$DC,$CC,$6E,$E6,$DD,$DD,$D9,$99
DB $BB,$BB,$67,$63,$6E,$0E,$EC,$CC,$DD,$DC,$99,$9F,$BB,$B9,$33,$3E
ENDM
ENDC ;HARDWARE_INC

BIN
src/.actor.asm.swp Normal file

Binary file not shown.

BIN
src/.animation.asm.swo Normal file

Binary file not shown.

BIN
src/.entry.asm.swp Normal file

Binary file not shown.

59
src/actor.asm Normal file
View File

@ -0,0 +1,59 @@
;-----------------
; Actor Animation
;-----------------
SECTION "Actor Variables Struct", WRAM, ALIGN[8]
wWorldX: dw
wWorldY: dw
wActorState: db
wActorCounter: db
wActorData: dw
wActorTile: dw
SECTION "Actor", ROM0
Actor::
.structs:
dw ActorIdle
.tiles:
ActorIdle::
db 60
dw .framePa
db 15
dw .frameRe
db 15
dw .frameCi
db 15
dw .frameVo
.framePa
db (.framePaEnd - @) / 4
db -8, -8, 1, 0
db -8, 0, 2, 0
db 0, -8, 9, 0
db 0, 0, 10, 0
.framePaEnd
.frameRe
db (.frameReEnd - @) / 4
db -8, -8, 3, 0
db -8, 0, 4, 0
db 0, -8, 11, 0
db 0, 0, 12, 0
.frameReEnd
.frameCi
db (.frameCiEnd - @) / 4
db -8, -8, 5, 0
db -8, 0, 6, 0
db 0, -8, 13, 0
db 0, 0, 14, 0
.frameCiEnd
.frameVo
db (.frameVoEnd - @) / 4
db -8, -8, 7, 0
db -8, 0, 8, 0
db 0, -8, 15, 0
db 0, 0, 16, 0
.frameVoEnd

59
src/animation.asm Normal file
View File

@ -0,0 +1,59 @@
;----------------
; Animation Subs
;----------------
SECTION "Animation Variables", HRAM
hCameraX: dw
hCameraY: dw
hWorkingX: dw
hWorkingY: dw
hWorkingScreenX: db
hWorkingScreenY: db
hWorkingState: db
hWorkingCounter: db
hWorkingData: dw
hWorkingTile: dw
hWorkingEnd:
SECTION "Animations Subs", ROM0
; RenderActor:
; takes a pointer to an actor struct
; and renders it to shadow OAM, advancinc
; the animation frame and constructing
; each frame as needed.
; initial input:
; [hl] <- start of Actor Struct in WRAM
; output:
; an oam object for each line in the frame data,
; copied to shadowOAM (wShadowOAM)
RenderActor::
; load world X and Y to temp RAM
ld a, [hli]
ld [hWorkingX], a
ld a, [hli]
ld [hWorkingX+1], a
ld a, [hli]
ld [hWorkingY], a
ld a, [hli]
ld [hWorkingY+1], a
; done loading X and Y
; figure out if within 256 of camera
; ---------
; first compare upper byte of XXYY
; if this is more than 1 away, break
ld a, [hCameraX]
ld b, a
ld a, [hWorkingX]
; b = camera byte
; a = actor byte
; work out if actor minus camera is <= 1
sub b
; ---------
.skipRendering

33
src/defines.asm Normal file
View File

@ -0,0 +1,33 @@
;----------------
; Definitions
;----------------
P1F_NONE EQU $30
P1F_BUTTONS EQU $10
P1F_DPAD EQU $20
;----------------
; RAM Vars
;----------------
SECTION "ROM Vars", ROM0
dPlayerWidth: db 2
dPlayerHeight: db 2
dPlayerSpriteTiles: db $01, $02, $09, $0A
SECTION "WRAM Vars", WRAM0[$C000]
X: dw
N: dw
ANS: db
rPlayerX: db
rPlayerY: db
SECTION "HRAM Vars", HRAM
hVBlankFlag: db
hCurKeys: db
hNewKeys: db

59
src/dma.asm Normal file
View File

@ -0,0 +1,59 @@
;------------------
; DMA Subroutines
;------------------
; In order to use, simply put your destination
; address into the `a` register, and call `hOAMDMA`
; Here we copy our DMA Routine into
; HRAM, which it needs to be in so
; it can function.
; Note: we can only copy into HRAM
; while the screen /ISN'T/ updating
SECTION "OAM DMA Routine", ROM0
; A DMA Transfor takes 160 microseconds
; to complete, which is 40 machine cycles.
; here we copy the high bit of our destination
; address (stored in a) to the DMA register
; then wait the time needed for the copy to
; complete.
DMARoutine:
ldh [rDMA], a
ld a, 40
.wait
dec a
jr nz, .wait
ret
.end
CopyDMARoutine:
ld hl, DMARoutine
ld b, DMARoutine.end - DMARoutine
ld c, LOW(hOAMDMA)
.copy
ld a, [hli]
ldh [c], a
inc c
dec b
jr nz, .copy
ret
; We reserve space in HRAM to keep our
; DMA routine.
SECTION "OAM DMA", HRAM
hOAMDMA:
ds DMARoutine.end - DMARoutine
; We also reserve space to have a copy
; of OAM that we can write to at any time
; The DMA will then mirror this data to
; the real OAM.
SECTION "Shadow OAM", WRAM0,ALIGN[8]
wShadowOAM::
ds 4*40

160
src/entry.asm Normal file
View File

@ -0,0 +1,160 @@
;----------------
; Program Start
;----------------
BUFFER EQU 160
TRUE EQU $42
FALSE EQU $69
SECTION "Program Start", ROM0[$150]
Start:
ei
ld a, IEF_VBLANK
ld [rIE], a
xor a
ld [hVBlankFlag], a
call Wait_VBlank
xor a
ldh [rLCDC], a
call Clear_Map
call Load_Tiles
; call Load_Map
ld a, %11100100
ld [rBGP], a
ld [rOBP0], a
xor a
ld [rSCY], a
ld [rSCX], a
ld [rNR52], a
ld a, LCDCF_ON | LCDCF_OBJON | LCDCF_BGON
ld [rLCDC], a
call CopyDMARoutine
ld a, 72
ld [rPlayerX], a
ld a, 88
ld [rPlayerY], a
;----
; Testing
;----
ld a, HIGH(ANS)
ld h, a
ld a, LOW(ANS)
ld l, a
; Case One: Camera@E100 vs Actor@E195 (Pass)
ld a, $E1
ld [N], a
ld a, $E1
ld [X], a
ld a, $00
ld [N+1], a
ld a, $95
ld [X+1], a
call CheckBoundry
; Case One: Camera@E095 vs Actor@E120 (Pass)
ld a, $E0
ld [N], a
ld a, $E1
ld [X], a
ld a, $95
ld [N+1], a
ld a, $20
ld [X+1], a
call CheckBoundry
; Case One: Camera@E100 vs Actor@E1FF (Fail)
ld a, $E1
ld [N], a
ld a, $E1
ld [X], a
ld a, $00
ld [N+1], a
ld a, $FF
ld [X+1], a
call CheckBoundry
; Case One: Camera@E1F0 vs Actor@E2DE (Fail)
ld a, $E1
ld [N], a
ld a, $E2
ld [X], a
ld a, $F0
ld [N+1], a
ld a, $DE
ld [X+1], a
call CheckBoundry
game_loop:
call Wait_VBlank
call Read_Pad
call PC_Update
call Player_To_OAM
ld a, HIGH(wShadowOAM)
call hOAMDMA
jr game_loop
CheckBoundry::
;-----
; Check if word X is within BUFFER ahead of N
; BUFFER is always <= 255
; hl contains address to save result to
;-----
;= load high bytes
ld a, [N]
ld b, a
ld a, [X]
sub b
;= if carry is set, N is behind X, so skip
jr c, .skipRender
ld b, a
ld a, 2
cp b
;= if the difference is 2 or greater
;= we are not within BUFFER, so skip
jr c, .skipRender
jr z, .skipRender
dec a
cp b
;= if the high byte differ by 1, we
;= need to check over a a page
jr z, .swap
;= load the low bytes
ld a, [N+1]
ld b, a
ld a, [X+1]
sub b
ld b, a
ld a, BUFFER
cp b
;= if the difference is greater than
;= the buffer, skip
jr c, .skipRender
jr .render
.swap
;= load the low bytes in the opposite order
ld a, [X+1]
ld b, a
ld a, [N+1]
sub b
ld b, a
ld a, $FF - BUFFER
cp b
;= if they differ by the inverse of the buffer
;= they will not be within the gap between pages
jr nc, .skipRender
.render
;= success, do rendering stuff
; beep boop rendering stuff
ld a, TRUE
ld [hli], a
ret
.skipRender
;= failure, skip this one
; doing other stuff here
ld a, FALSE
ld [hli], a
ret

45
src/header.asm Normal file
View File

@ -0,0 +1,45 @@
;-----------------
; Gameboy Header
;-----------------
SECTION "Header", ROM0[$100]
; Jump to the "Start" label
; which we must define ourselves
EntryPoint:
nop
jp Start;
; ROM Header $104 to $150
RomHeader:
; Nintendo Logo $104-$133
db $CE,$ED,$66,$66,$CC,$0D,$00,$0B,$03,$73,$00,$83,$00,$0C,$00,$0D
db $00,$08,$11,$1F,$88,$89,$00,$0E,$DC,$CC,$6E,$E6,$DD,$DD,$D9,$99
db $BB,$BB,$67,$63,$6E,$0E,$EC,$CC,$DD,$DC,$99,$9F,$BB,$B9,$33,$3E
; Title (11 characters) $134-$13E
db "ANIMATION",$00,$00
; Manufacturer Code (4 characters) $13F-$142
db "LATA"
; CGB Flag $143
db $00
; Licensee Code (2 characters) $144-$145
db "00"
; SGB Flag $146
db $00
; Cartridge Type $147
db $00
; ROM Size $148
db $00
; RAM Size $149
db $00
; Destination Code $14A
db $01
; Depreciated Licensee Code $14B
db $33
; Version Number $14C
db $00
; Header Checksum $14D
db $00
; Global Checksum $14E-$14F
db $00, $00

11
src/main.asm Normal file
View File

@ -0,0 +1,11 @@
INCLUDE "inc/hardware.inc"
INCLUDE "ass/parecivo.ass"
INCLUDE "ass/tiles.ass"
INCLUDE "ass/map.ass"
INCLUDE "src/entry.asm"
INCLUDE "src/header.asm"
INCLUDE "src/defines.asm"
INCLUDE "src/dma.asm"
INCLUDE "src/util.asm"
INCLUDE "src/vid.asm"
INCLUDE "src/misc.asm"

167
src/misc.asm Normal file
View File

@ -0,0 +1,167 @@
Player_To_OAM:
; -- first loop --
ld hl, wShadowOAM
ld a, [dPlayerHeight]
ld b, a
ld d, 16
ld a, [rPlayerY]
add d ; d has the base Y value (counting offsets)
ld d, a
.fouter
ld a, [dPlayerWidth]
ld c, a ; c is finner counter
.finner
ld a, d
ld [hl], a
ld a, 4
call .add4hl
; end of finner loop
dec c
jr nz, .finner
ld a, d
ld d, 8
add d
ld d, a
; end of fouter loop
dec b
jr nz, .fouter
; -- second loop --
ld hl, wShadowOAM+1
ld a, [dPlayerHeight]
ld b, a
.souter
ld d, 8
ld a, [rPlayerX]
add d
ld d, a
ld a, [dPlayerWidth]
ld c, a
.sinner
ld a, d
ld [hl], a
add 8
ld d, a
ld a, 4
call .add4hl
dec c
jr nz, .sinner
dec b
jr nz, .souter
; -- third loop --
ld hl, wShadowOAM+2
ld de, dPlayerSpriteTiles
ld a, [dPlayerHeight]
ld b, a
ld a, [dPlayerWidth]
ld c, a
xor a
.tloop1
add b
dec c
jr nz, .tloop1
ld c, a
.tloop2
ld a, [de]
ld [hl], a
ld a, 4
call .add4hl
inc de
dec c
jr nz, .tloop2
; -- fourth loop --
ld hl, wShadowOAM+3
ld a, [dPlayerHeight]
ld b, a
ld a, [dPlayerWidth]
ld c, a
xor a
.lloop1
add b
dec c
jr nz, .lloop1
ld c, a
.lloop2
xor a
ld [hl], a
ld a, 4
call .add4hl
dec c
jr nz, .lloop2
ret
.add4hl:
add a, l ; a = low + old_l
ld l, a ; a = low + old_l = new_l
adc a, h ; a = new_l + old_h + carry
sub l ; a = old_h + carry
ld h, a
ret
PC_Update:
ld b, 0
ld c, 0
ld a, [hCurKeys]
and %10000000
cp %10000000 ; 0 if down pressed
jr nz, .up
ld b, 1
.up:
ld a, [hCurKeys]
and %01000000
cp %01000000 ; 0 if up pressed
jr nz, .left
ld b, 255
.left:
ld a, [hCurKeys]
and %00100000
cp %00100000 ; 0 if down pressed
jr nz, .right
ld c, 255
.right:
ld a, [hCurKeys]
and %00010000
cp %00010000 ; 0 if up pressed
jr nz, .last
ld c, 1
.last:
ld a, [rPlayerX]
add c
ld [rPlayerX], a
ld a, [rPlayerY]
add b
ld [rPlayerY], a
.end:
ret
Clear_Map:
xor a
ld hl, _SCRN0
ld bc, _SCRN0_END - _SCRN0
.loop:
ld [hli], a
dec bc
ld a, b
or c
jr z, .loop
ret
Load_Tiles:
ld hl, _BGTILES
ld de, parecivo_tile_data
ld bc, parecivo_tile_data_size
call MemCpy
ld hl, _VRAM
ld de, parecivo_tile_data
ld bc, parecivo_tile_data_size
call MemCpy
ret
Load_Map:
ld hl, _SCRN0
ld de, Map
ld bc, Map_Size
call MemCpy
ret

70
src/util.asm Normal file
View File

@ -0,0 +1,70 @@
;----------------------
; Utility Subroutines
;----------------------
SECTION "Util Subs", ROM0
; MemCpy assumes:
; hl contains destination address
; de contains source address
; bc contains number of bytes to copy
MemCpy:
.copy
ld a, [de]
ld [hli], a
inc de
dec bc
ld a, b
or c
jr nz, .copy
ret
; Read_Pad will set the variable _PAD
; such that bits are as follows:
; 7 - 4: down up left right
; 3 - 0: start select b a
Read_Pad:
ld a,P1F_BUTTONS
call .onenibble
ld b,a ; B7-4 = 1; B3-0 = unpressed buttons
ld a,P1F_DPAD
call .onenibble
swap a ; A3-0 = unpressed directions; A7-4 = 1
xor b ; A = pressed buttons + directions
ld b,a ; B = pressed buttons + directions
; check illegal buttons
and %11000000 ; Up and Down buttons
cp %11000000
jr nz, .legalUpDown
ld a, b
and %00111111
ld b, a
.legalUpDown
and %00110000 ; Left and Right buttons
cp %00110000
jr nz, .legalLeftRight
ld a, b
and %11001111
.legalLeftRight
ld a,P1F_NONE
ld [rP1],a
ldh a,[hCurKeys]
xor b ; A = keys that changed state
and b ; A = keys that changed to pressed
ldh [hNewKeys],a
ld a,b
ldh [hCurKeys],a
ret
.onenibble:
ldh [rP1],a
ldh a,[rP1]
ldh a,[rP1]
ldh a,[rP1]
or $F0
ret

22
src/vid.asm Normal file
View File

@ -0,0 +1,22 @@
;--------------------
; Video Subroutines
;--------------------
SECTION "VBlank Int", ROM0[$40]
ld a, 1
ld [hVBlankFlag], a
reti
SECTION "Vid Subs", ROM0
Wait_VBlank::
ld hl, hVBlankFlag ; hl=pointer to vblank_flag
.wait: ; wait...
halt ; suspend CPU - wait for ANY interrupt
nop
xor a
cp a,[hl] ; vblank flag still zero?
jr z, .wait ; wait more if zero
ld [hl],a ; set vblank_flag back to zero
ret

54
testing/ISSOtm.asm Normal file
View File

@ -0,0 +1,54 @@
PlayerGfx::
INCLUDE "res/actors/player.pal.asm" ; CGB palette
db OAMF_PAL1 ; Additional attr
dw PlayerTiles
PlayerTiles:
; number of tiles:
db (.displayStructs - .tiles) / 16
.tiles
INCBIN "res/actors/player.2bpp"
.displayStructs
dw PlayerStandingUp
dw PlayerWalkingUp
dw PlayerStandingDown
dw PlayerWalkingDown
dw PlayerStandingLeft
dw PlayerWalkingLeft
dw PlayerStandingRight
dw PlayerWalkingRight
PlayerWalkingDown:
db $20
db 8
dw .frame0
db 8
dw .frame1
db 8
dw .frame0
db 8
dw .frame2
.frame0
db (.frame0End - @) / 4
db -31, -8, 0, 0
db -15, -8, 2, 0
db -31, 0, 4, 0
db -15, 0, 6, 0
.frame0End
.frame1
db (.frame1End - @) / 4
db -31, -8, 8, 0
db -15, -8, 10, 0
db -31, 0, 12, 0
db -15, 0, 14, 0
.frame1End
.frame2
db (.frame2End - @) / 4
db -31, -8, 16, 0
db -15, -8, 18, 0
db -31, 0, 20, 0
db -15, 0, 22, 0
.frame2End