                              1 	.include	"global.s"
                    0001      1 	.NEAR_CALLS = 1         ; <near_calls> - tag so that sed can change this
                              2         
                              3 	;; Changed by astorgb.pl to 1
                    0000      4 	__RGBDS__	= 0
                              5 
                              6 	
                              7 	;;  Screen dimensions 
                    0013      8 	.MAXCURSPOSX	= 0x13	; In tiles
                    0011      9 	.MAXCURSPOSY	= 0x11
                             10 
                    0080     11 	.START		= 0x80
                    0040     12 	.SELECT		= 0x40
                    0020     13 	.B		= 0x20
                    0010     14 	.A		= 0x10
                    0008     15 	.DOWN		= 0x08
                    0004     16 	.UP		= 0x04
                    0002     17 	.LEFT		= 0x02
                    0001     18 	.RIGHT		= 0x01
                             19 
                    00A0     20 	.SCREENWIDTH	= 0xA0
                    0090     21 	.SCREENHEIGHT	= 0x90
                    0007     22 	.MINWNDPOSX	= 0x07
                    0000     23 	.MINWNDPOSY	= 0x00
                    00A6     24 	.MAXWNDPOSX	= 0xA6
                    008F     25 	.MAXWNDPOSY	= 0x8F
                             26 
                    0001     27 	.VBL_IFLAG	= 0x01
                    0002     28 	.LCD_IFLAG	= 0x02
                    0004     29 	.TIM_IFLAG	= 0x04
                    0008     30 	.SIO_IFLAG	= 0x08
                    0010     31 	.JOY_IFLAG	= 0x10
                             32  
                    0000     33 	.P1		= 0x00	; Joystick: 1.1.P15.P14.P13.P12.P11.P10
                    0001     34 	.SB		= 0x01	; Serial IO data buffer
                    0002     35 	.SC		= 0x02	; Serial IO control register
                    0004     36 	.DIV		= 0x04	; Divider register
                    0005     37 	.TIMA		= 0x05	; Timer counter
                    0006     38 	.TMA		= 0x06	; Timer modulo
                    0007     39 	.TAC		= 0x07	; Timer control
                    000F     40 	.IF		= 0x0F	; Interrupt flags: 0.0.0.JST.SIO.TIM.LCD.VBL
                    0010     41 	.NR10		= 0x10	; Sound register
                    0011     42 	.NR11		= 0x11	; Sound register
                    0012     43 	.NR12		= 0x12	; Sound register
                    0013     44 	.NR13		= 0x13	; Sound register
                    0014     45 	.NR14		= 0x14	; Sound register
                    0016     46 	.NR21		= 0x16	; Sound register
                    0017     47 	.NR22		= 0x17	; Sound register
                    0018     48 	.NR23		= 0x18	; Sound register
                    0019     49 	.NR24		= 0x19	; Sound register
                    001A     50 	.NR30		= 0x1A	; Sound register
                    001B     51 	.NR31		= 0x1B	; Sound register
                    001C     52 	.NR32		= 0x1C	; Sound register
                    001D     53 	.NR33		= 0x1D	; Sound register
                    001E     54 	.NR34		= 0x1E	; Sound register
                    0020     55 	.NR41		= 0x20	; Sound register
                    0021     56 	.NR42		= 0x21	; Sound register
                    0022     57 	.NR43		= 0x22	; Sound register
                    0023     58 	.NR44		= 0x23	; Sound register
                    0024     59 	.NR50		= 0x24	; Sound register
                    0025     60 	.NR51		= 0x25	; Sound register
                    0026     61 	.NR52		= 0x26	; Sound register
                    0040     62 	.LCDC		= 0x40	; LCD control
                    0041     63 	.STAT		= 0x41	; LCD status
                    0042     64 	.SCY		= 0x42	; Scroll Y
                    0043     65 	.SCX		= 0x43	; Scroll X
                    0044     66 	.LY		= 0x44	; LCDC Y-coordinate
                    0045     67 	.LYC		= 0x45	; LY compare
                    0046     68 	.DMA		= 0x46	; DMA transfer
                    0047     69 	.BGP		= 0x47	; BG palette data
                    0048     70 	.OBP0		= 0x48	; OBJ palette 0 data
                    0049     71 	.OBP1		= 0x49	; OBJ palette 1 data
                    004A     72 	.WY		= 0x4A	; Window Y coordinate
                    004B     73 	.WX		= 0x4B	; Window X coordinate
                    004D     74 	.KEY1		= 0x4D	; CPU speed
                    004F     75 	.VBK		= 0x4F	; VRAM bank
                    0051     76 	.HDMA1		= 0x51	; DMA control 1
                    0052     77 	.HDMA2		= 0x52	; DMA control 2
                    0053     78 	.HDMA3		= 0x53	; DMA control 3
                    0054     79 	.HDMA4		= 0x54	; DMA control 4
                    0055     80 	.HDMA5		= 0x55	; DMA control 5
                    0056     81 	.RP		= 0x56	; IR port
                    0068     82 	.BCPS		= 0x68	; BG color palette specification
                    0069     83 	.BCPD		= 0x69	; BG color palette data
                    006A     84 	.OCPS		= 0x6A	; OBJ color palette specification
                    006B     85 	.OCPD		= 0x6B	; OBJ color palette data
                    0070     86 	.SVBK		= 0x70	; WRAM bank
                    00FF     87 	.IE		= 0xFF	; Interrupt enable
                             88 
                    0001     89 	.G_MODE		= 0x01	; Graphic mode
                    0002     90 	.T_MODE		= 0x02	; Text mode (bit 2)
                    0002     91 	.T_MODE_OUT	= 0x02	; Text mode output only
                    0003     92 	.T_MODE_INOUT	= 0x03	; Text mode with input
                    0004     93 	.M_NO_SCROLL	= 0x04	; Disables scrolling of the screen in text mode
                    0008     94 	.M_NO_INTERP	= 0x08	; Disables special character interpretation
                             95 
                    2000     96 	.MBC1_ROM_PAGE	= 0x2000 ; Address to write to for MBC1 switching
                             97 	
                             98 	;; Status codes for IO
                    0000     99 	.IO_IDLE	= 0x00
                    0001    100 	.IO_SENDING	= 0x01
                    0002    101 	.IO_RECEIVING	= 0x02
                    0004    102 	.IO_ERROR	= 0x04
                            103 
                            104 	;; Type of IO data
                    0066    105 	.DT_IDLE	= 0x66
                    0055    106 	.DT_RECEIVING	= 0x55
                            107 
                            108 	;; Table of routines for modes
                    01E0    109 	.MODE_TABLE	= 0x01E0
                            110 
                            111 	;; C related
                            112 	;; Overheap of a banked call.  Used for parameters
                            113 	;;  = ret + real ret + bank
                            114 
                    0001    115 	.if .NEAR_CALLS
                    0002    116 	.BANKOV		= 2
                            117 
                            118 	.else
                            119 	.BANKOV		= 6
                            120 
                            121 	.endif
                            122 	
                            123 	.globl	banked_call
                            124 	.globl	banked_ret
                            125 	
                            126 	;; Global variables
                            127 	.globl	.mode
                            128 
                            129 	.globl	__cpu
                            130 
                            131 	.globl	__io_out
                            132 	.globl	__io_in
                            133 	.globl	__io_status
                            134 
                            135 	;; Global routines
                            136 	.globl	.set_mode
                            137 
                            138 	.globl	.reset
                            139 
                            140 	.globl	.display_off
                            141 
                            142 	.globl	.wait_vbl_done
                            143 
                            144 	;; Interrupt routines 
                            145 	.globl	.add_VBL
                            146 	.globl	.add_LCD
                            147 	.globl	.add_TIM
                            148 	.globl	.add_SIO
                            149 	.globl	.add_JOY
                            150 
                            151 	;; Symbols defined at link time
                            152 	.globl	.STACK
                            153 	.globl	.OAM
                            154 	.globl	.refresh_OAM
                            155 
                            156 	;; Initialization routine   
                            157 	.globl	.init
                            158 
                            159 	;; Main user routine	
                            160 	.globl	_main
                              2 
                              3 	;; BANKED:	checked, imperfect
                              4 	.area	_BASE
                              5 
   0000                       6 _scroll_bkg::
   0000 F8 02                 7 	LDA	HL,2(SP)	; Skip return address
   0002 AF                    8 	XOR	A
   0003 BE                    9 	CP	(HL)		; Is x != 0
   0004 28 05                10 	JR	Z,1$
                             11 
   0006 F0 43                12 	LDH	A,(.SCX)	; Yes
   0008 86                   13 	ADD	(HL)
   0009 E0 43                14 	LDH	(.SCX),A
   000B                      15 1$:
   000B 23                   16 	INC	HL
   000C AF                   17 	XOR	A
   000D BE                   18 	CP	(HL)		; Is y != 0
   000E 28 05                19 	JR	Z,2$
                             20 
   0010 F0 42                21 	LDH	A,(.SCY)	; Yes
   0012 86                   22 	ADD	(HL)
   0013 E0 42                23 	LDH	(.SCY),A
   0015                      24 2$:
   0015 C9                   25 	RET
