global.s (16483B)
1 .OS_RESET = 0x0000 2 .LS_IO = 0x0003 3 .LS_DSK = 0x0004 4 .LS_INT_VECTOR = 0x0038 5 .LS_FCB0 = 0x005C 6 .LS_FCB1 = 0x006C 7 .LS_FILE_BUFFER = 0x0080 8 .BDOS = 0x0005 9 10 .EXTBIO = 0xFFCA 11 12 ; MSX-DOS 1 13 _TERM0 = 0x00 ; Program terminate 14 _CONIN = 0x01 ; Console input 15 _CONOUT = 0x02 ; Console output 16 _AUXIN = 0x03 ; Auxiliary input 17 _AUXOUT = 0x04 ; Auxiliary output 18 _LSTOUT = 0x05 ; Printer output 19 _DIRIO = 0x06 ; Direct console I/O 20 _DIRIN = 0x07 ; Direct console input 21 _INNOE = 0x08 ; Console input without echo 22 _STROUT = 0x09 ; String output 23 _BUFIN = 0x0A ; Buffered line input 24 _CONST = 0x0B ; Console status 25 _CPMVER = 0x0C ; Return version number 26 _DSKRST = 0x0D ; Disk reset 27 _SELDSK = 0x0E ; Select disk 28 _FOPEN = 0x0F ; Open file (FCB) 29 _FCLOSE = 0x10 ; Close file (FCB) 30 _SFIRST = 0x11 ; Search for first entry (FCB) 31 _SNEXT = 0x12 ; Search for next entry (FCB) 32 _FDEL = 0x13 ; Delete file (FCB) 33 _RDSEQ = 0x14 ; Sequential read (FCB) 34 _WRSEQ = 0x15 ; Sequential write (FCB) 35 _FMAKE = 0x16 ; Create file (FCB) 36 _FREN = 0x17 ; Rename file (FCB) 37 _LOGIN = 0x18 ; Get login vector 38 _CURDRV = 0x19 ; Get current drive 39 _SETDTA = 0x1A ; Set disk transfer address 40 _ALLOC = 0x1B ; Get allocation information 41 _RDRND = 0x21 ; Random read (FCB) 42 _WRRND = 0x22 ; Random write (FCB) 43 _FSIZE = 0x23 ; Get file size (FCB) 44 _SETRND = 0x24 ; Set random record (FCB) 45 _WRBLK = 0x26 ; Random block write (FCB) 46 _RDBLK = 0x27 ; Random block read (FCB) 47 _WRZER = 0x28 ; Random write with zero fill (FCB) 48 _GDATE = 0x2A ; Get date 49 _SDATE = 0x2B ; Set date 50 _GTIME = 0x2C ; Get time 51 _STIME = 0x2D ; Set time 52 _VERIFY = 0x2E ; Set/reset verify flag 53 _RDABS = 0x2F ; Absolute sector read 54 _WRABS = 0x30 ; Absolute sector write 55 56 ; MSX-DOS2 57 _DPARM = 0x31 ; Get disk parameters 58 _FFIRST = 0x40 ; Find first entry 59 _FNEXT = 0x41 ; Find next entry 60 _FNEW = 0x42 ; Find new entry 61 _OPEN = 0x43 ; Open file handle 62 _CREATE = 0x44 ; Create file handle 63 _CLOSE = 0x45 ; Close file handle 64 _ENSURE = 0x46 ; Ensure file handle 65 _DUP = 0x47 ; Duplicate file handle 66 _READ = 0x48 ; Read from file handle 67 _WRITE = 0x49 ; Write to file handle 68 _SEEK = 0x4A ; Move file handle pointer 69 _IOCTL = 0x4B ; I/O control for devices 70 _HTEST = 0x4C ; Test file handle 71 _DELETE = 0x4D ; Delete file or subdirectory 72 _RENAME = 0x4E ; Rename file or subdirectory 73 _MOVE = 0x4F ; Move file or subdirectory 74 _ATTR = 0x50 ; Get/set file attributes 75 _FTIME = 0x51 ; Get/set file date and time 76 _HDELETE = 0x52 ; Delete file handle 77 _HRENAME = 0x53 ; Rename file handle 78 _HMOVE = 0x54 ; Move file handle 79 _HATTR = 0x55 ; Get/set file handle attributes 80 _HFTIME = 0x56 ; Get/set file handle date and time 81 _GETDTA = 0x57 ; Get disk transfer address 82 _GETVFY = 0x58 ; Get verify flag setting 83 _GETCD = 0x59 ; Get current directory 84 _CHDIR = 0x5A ; Change current directory 85 _PARSE = 0x5B ; Parse pathname 86 _PFILE = 0x5C ; Parse filename 87 _CHKCHR = 0x5D ; Check character 88 _WPATH = 0x5E ; Get whole path string 89 _FLUSH = 0x5F ; Flush disk buffers 90 _FORK = 0x60 ; Fork a child process 91 _JOIN = 0x61 ; Rejoin parent process 92 _TERM = 0x62 ; Terminate with error code 93 _DEFAB = 0x63 ; Define abort exit routine 94 _DEFER = 0x64 ; Define disk error handler routine 95 _ERROR = 0x65 ; Get previous error code 96 _EXPLAIN = 0x66 ; Explain error code 97 _FORMAT = 0x67 ; Format a disk 98 _RAMD = 0x68 ; Create or destroy RAM disk 99 _BUFFER = 0x69 ; Allocate sector buffers 100 _ASSIGN = 0x6A ; Logical drive assignment 101 _GENV = 0x6B ; Get environment item 102 _SENV = 0x6C ; Set environment item 103 _FENV = 0x6D ; Find environment item 104 _DSKCHK = 0x6E ; Get/set disk check status 105 _DOSVER = 0x6F ; Get MSX-DOS version number 106 _REDIR = 0x70 ; Get/set redirection status 107 108 ; MSX_DOS ERROR CODES 109 .NCOMP = 0xFF ; Incompatible disk 110 .WRERR = 0xFE ; Write error 111 .DISK = 0xFD ; Disk error 112 .NRDY = 0xFC ; Not ready 113 .VERFY = 0xFB ; Verify error 114 .DATA = 0xFA ; Data error 115 .RNF = 0xF9 ; Sector not found 116 .WPROT = 0xF8 ; Write protected disk 117 .UFORM = 0xF7 ; Unformatted disk 118 .NDOS = 0xF6 ; Not a DOS disk 119 .WDISK = 0xF5 ; Wrong disk 120 .WFILE = 0xF4 ; Wrong disk for file 121 .SEEK = 0xF3 ; Seek error 122 .IFAT = 0xF2 ; Bad file allocation table 123 .NOUPB = 0xF1 ; -- 124 .IFORM = 0xF0 ; Cannot format this drive 125 .INTER = 0xDF ; Internal error 126 .NORAM = 0xDE ; Not enough memory 127 .IBDOS = 0xDC ; Invalid MSX-DOS call 128 .IDRV = 0xDB ; Invalid drive 129 .IFNM = 0xDA ; Invalid filename 130 .IPATH = 0xD9 ; Invalid pathname 131 .PLONG = 0xD8 ; Pathname too long 132 .NOFIL = 0xD7 ; File not found 133 .NODIR = 0xD6 ; Directory not found 134 .DRFUL = 0xD5 ; Root directory full 135 .DKFUL = 0xD4 ; Disk full 136 .DUPF = 0xD3 ; Duplicate filename 137 .DIRE = 0xD2 ; Invalid directory move 138 .FILRO = 0xD1 ; Read only file 139 .DIRNE = 0xD0 ; Directory not empty 140 .IATTR = 0xCF ; Invalid attributes 141 .DOT = 0xCE ; Invalid . or .. operation 142 .SYSX = 0xCD ; System file exists 143 .DIRX = 0xCC ; Directory exists 144 .FILEX = 0xCB ; File exists 145 .FOPEN = 0xCA ; File already in use 146 .OV64K = 0xC9 ; Cannot transfer above 64K 147 .FILE = 0xC8 ; File allocation error 148 .EOF = 0xC7 ; End of file 149 .ACCV = 0xC6 ; File access violation 150 .IPROC = 0xC5 ; Invalid process id 151 .NHAND = 0xC4 ; No spare file handles 152 .IHAND = 0xC3 ; Invalid file handle 153 .NOPEN = 0xC2 ; File handle not open 154 .IDEV = 0xC1 ; Invalid device operation 155 .IENV = 0xC0 ; Invalid environment string 156 .ELONG = 0xBF ; Environment string too long 157 .IDATE = 0xBE ; Invalid date 158 .ITIME = 0xBD ; Invalid time 159 .RAMDX = 0xBC ; RAM disk (drive H ) already exists 160 .NRAMD = 0xBB ; RAM disk does not exist 161 .HDEAD = 0xBA ; File handle has been deleted 162 .EOL = 0xB9 ; Internal error. Should never occur 163 .ISBFN = 0xB8 ; Invalid sub-function number 164 .STOP = 0x9F ; Ctrl-STOP pressed 165 .CTRLC = 0x9E ; Ctrl-C pressed 166 .ABORT = 0x9D ; Disk operation aborted 167 .OUTERR = 0x9C ; Error on standard output 168 .INERR = 0x9B ; Error on standard input 169 .BADCOM = 0x8F ; Wrong version of COMMAND 170 .BADCM = 0x8E ; Unrecognized command 171 .BUFUL = 0x8D ; Command too long 172 .OKCMD = 0x8C ; -- 173 .IPARM = 0x8B ; Invalid parameter 174 .INP = 0x8A ; Too many parameters 175 .NOPAR = 0x89 ; Missing parameter 176 .IOPT = 0x88 ; Invalid option 177 .BADNO = 0x87 ; Invalid number 178 .NOHELP = 0x86 ; File for HELP not found 179 .BADVER = 0x85 ; Wrong version of MSX-DOS 180 .NOCAT = 0x84 ; Cannot concatenate destination file 181 .BADEST = 0x83 ; Cannot create destination file 182 .COPY = 0x82 ; File cannot be copied onto itself 183 .OVDEST = 0x81 ; Cannot overwrite previous destination file 184 185 .MEMORY_CTL = 0x3E 186 187 .MEMCTL_JOYON = 0b00000000 188 .MEMCTL_JOYOFF = 0b00000100 189 .MEMCTL_BASEON = 0b00000000 190 .MEMCTL_BASEOFF = 0b00001000 191 .MEMCTL_RAMON = 0b00000000 192 .MEMCTL_RAMOFF = 0b00010000 193 .MEMCTL_CROMON = 0b00000000 194 .MEMCTL_CROMOFF = 0b00100000 195 .MEMCTL_ROMON = 0b00000000 196 .MEMCTL_ROMOFF = 0b01000000 197 .MEMCTL_EXTON = 0b00000000 198 .MEMCTL_EXTOFF = 0b10000000 199 200 .JOY_CTL = 0x3F 201 202 .JOY_P1_LATCH = 0b00000010 203 .JOY_P2_LATCH = 0b00001000 204 205 .VDP_VRAM = 0x4000 206 .VDP_TILEDATA0 = 0x4000 207 .VDP_TILEDATA1 = 0x4800 208 .VDP_TILEDATA2 = 0x5000 209 .VDP_COLORDATA0 = 0x6000 210 .VDP_COLORDATA1 = 0x6800 211 .VDP_COLORDATA1 = 0x7000 212 213 .VDP_SPRDATA0 = 0x7800 214 215 .VDP_TILEMAP = 0x5C00 216 .VDP_CRAM = 0xC000 217 .VDP_SAT = 0x5B00 218 219 .VDP_SAT_TERM = 0xD0 220 221 .VDP_VCOUNTER = 0x7E 222 .VDP_PSG = 0x7F 223 .VDP_HCOUNTER = 0x7F 224 225 .VDP_DATA = 0x98 226 .VDP_CMD = 0x99 227 .VDP_STAT = 0x99 228 229 .STATF_INT_VBL = 0b10000000 230 .STATF_9_SPR = 0b01000000 231 .STATF_SPR_COLL = 0b00100000 232 233 .VDP_REG_MASK = 0b10000000 234 .VDP_R0 = 0b10000000 235 236 .R0_DEFAULT = 0b00000000 237 .R0_CB_OUTPUT = 0b00000000 238 .R0_CB_INPUT = 0b01000000 239 .R0_IE2_OFF = 0b00000000 240 .R0_IE2 = 0b00100000 241 .R0_IE1_OFF = 0b00000000 242 .R0_IE1 = 0b00010000 243 .R0_SCR_MODE1 = 0b00000000 244 .R0_SCR_MODE2 = 0b00000010 245 .R0_ES_OFF = 0b00000000 246 .R0_ES = 0b00000001 247 248 .VDP_R1 = 0b10000001 249 250 .R1_DEFAULT = 0b10000000 251 .R1_DISP_OFF = 0b00000000 252 .R1_DISP_ON = 0b01000000 253 .R1_IE_OFF = 0b00000000 254 .R1_IE = 0b00100000 255 .R1_SCR_MODE1 = 0b00010000 256 .R1_SCR_MODE2 = 0b00000000 257 .R1_SCR_MODE3 = 0b00000000 258 .R1_SPR_8X8 = 0b00000000 259 .R1_SPR_16X16 = 0b00000010 260 .R1_SPR_MAG = 0b00000001 261 .R1_SPR_MAG_OFF = 0b00000000 262 263 .VDP_R2 = 0b10000010 264 265 .R2_MAP_0x1C00 = 0x07 266 267 .VDP_R3 = 0b10000011 268 .VDP_R4 = 0b10000100 269 .VDP_R5 = 0b10000101 270 271 .R5_SAT_0x1B00 = 0x36 272 .R5_SAT_MASK = 0b10000001 273 274 .VDP_R6 = 0b10000110 275 276 .VDP_R7 = 0b10000111 277 .VDP_RBORDER = 0b10000111 278 279 .R7_COLOR_MASK = 0b11110000 280 281 .VDP_R8 = 0b10001000 282 283 .VDP_R9 = 0b10001001 284 285 .VDP_R10 = 0b10001010 286 287 .JOYPAD_COUNT = 1 288 289 .UP = 0b00100000 290 .DOWN = 0b01000000 291 .LEFT = 0b00010000 292 .RIGHT = 0b10000000 293 .A = 0b00000001 294 .B = 0b00000100 295 .SELECT = 0b00001000 296 .START = 0b00000010 297 298 .KBD_SELECT_ROW = 0xAA 299 .KBD_INPUT = 0xA9 300 301 .JOY_PORT1 = 0xDC 302 303 .JOY_P1_UP = 0b00000001 304 .JOY_P1_DOWN = 0b00000010 305 .JOY_P1_LEFT = 0b00000100 306 .JOY_P1_RIGHT = 0b00001000 307 .JOY_P1_SW1 = 0b00010000 308 .JOY_P1_TRIGGER = 0b00010000 309 .JOY_P1_SW2 = 0b00100000 310 .JOY_P2_UP = 0b01000000 311 .JOY_P2_DOWN = 0b10000000 312 313 .JOY_PORT2 = 0xDD 314 315 .JOY_P2_LEFT = 0b00000001 316 .JOY_P2_RIGHT = 0b00000010 317 .JOY_P2_SW1 = 0b00000100 318 .JOY_P2_TRIGGER = 0b00000100 319 .JOY_P2_SW2 = 0b00001000 320 .JOY_RESET = 0b00010000 321 .JOY_P1_LIGHT = 0b01000000 322 .JOY_P2_LIGHT = 0b10000000 323 324 .FMADDRESS = 0xF0 325 .FMDATA = 0xF1 326 .AUDIOCTRL = 0xF2 327 328 .MAP_FRAME0 = 0xfffc 329 .MAP_FRAME1 = 0xfffd 330 .MAP_FRAME2 = 0xfffe 331 .MAP_FRAME3 = 0xffff 332 333 .BIOS = 0xC000 334 335 .SYSTEM_PAL = 0x00 336 .SYSTEM_NTSC = 0x01 337 338 .CPU_CLOCK = 3579545 339 340 ;; GBDK library screen modes 341 342 .T_MODE = 0x02 ; Text mode (bit 2) 343 .T_MODE_OUT = 0x02 ; Text mode output only 344 .T_MODE_INOUT = 0x03 ; Text mode with input 345 .M_NO_SCROLL = 0x04 ; Disables scrolling of the screen in text mode 346 .M_NO_INTERP = 0x08 ; Disables special character interpretation 347 348 ;; Screen dimentions in tiles 349 350 .SCREEN_X_OFS = 0 351 .SCREEN_Y_OFS = 0 352 .SCREEN_WIDTH = 32 353 .SCREEN_HEIGHT = 24 354 .VDP_MAP_HEIGHT = 24 355 .VDP_MAP_WIDTH = 32 356 357 ;; Interrupt flags 358 359 .VBL_IFLAG = 0x01 360 .LCD_IFLAG = 0x02 361 362 ; characters 363 .CR = 0x0A 364 .SPACE = 0x00 365 366 ;; Main user routine 367 .globl _main 368 369 ;; interrupt handler 370 .globl _INT_ISR 371 372 ;; Macro definitions 373 374.macro CALL_BDOS fn 375 ld c, fn 376 call .BDOS 377.endm 378 379.macro JP_BDOS fn 380 ld c, fn 381 jp .BDOS 382.endm 383 384.macro VDP_WRITE_DATA regH regL ?lbl 385 ld a, i 386 ld a, regL 387 di 388 out (#.VDP_DATA), a ; 11 389 ld a, regH ; 4 390 jp po, lbl ; 7/12 391 ei ; 4 (total: 26/27) 392lbl: 393 out (#.VDP_DATA), a 394.endm 395 396.macro VDP_WRITE_CMD regH regL ?lbl 397 ld a, i 398 ld a, regL 399 di 400 out (#.VDP_CMD), a 401 ld a, regH 402 jp po, lbl 403 ei 404lbl: 405 out (#.VDP_CMD), a 406.endm 407 408.macro VDP_DELAY ?lbl 409 nop 410 jr lbl 411lbl: 412.endm 413 414.macro VDP_CANCEL_INT 415 in a, (.VDP_STAT) ; cancel pending VDP interrupts 416.endm 417 418.macro WRITE_VDP_CMD_HL 419 MSX_WRITE_VDP_CMD h, l 420.endm 421 422.macro WRITE_VDP_DATA_HL 423 MSX_WRITE_VDP_DATA h, l 424.endm 425 426.macro CALL_HL 427 call ___sdcc_call_hl 428.endm 429 430.macro DISABLE_VBLANK_COPY 431 ld a, #1 432 ld (__shadow_OAM_OFF), a 433.endm 434 435.macro ENABLE_VBLANK_COPY 436 xor a 437 ld (__shadow_OAM_OFF), a 438.endm 439 440.macro ADD_A_REG16 regH regL 441 add regL 442 ld regL, a 443 adc regH 444 sub regL 445 ld regH, a 446.endm 447 448.macro MUL_DE_BY_A_RET_HL ?lbl1 ?lbl2 449 ; Multiply DE by A, return result in HL; preserves: BC 450 ld hl, #0 451lbl1: 452 srl a 453 jp nc, lbl2 454 add hl, de 455lbl2: 456 sla e 457 rl d 458 or a 459 jp nz, lbl1 460.endm 461 462.macro DIV_PART divident divisor ?lbl 463 rl divident 464 rla 465 sub divisor 466 jr nc, lbl 467 add divisor 468lbl: 469.endm 470.macro FAST_DIV8 divident divisor 471 ; returns modulus in A 472 .rept 8 473 DIV_PART divident divisor 474 .endm 475 ld a, divident 476 cpl 477.endm 478.macro FAST_MOD8 divident divisor 479 ; returns modulus in A 480 .rept 8 481 DIV_PART divident divisor 482 .endm 483.endm