├── 01-HelloWorld ├── .gitignore ├── README.MD ├── build.sh ├── charmap.asm ├── fonts │ └── pixelfont.asm ├── globals.asm ├── init.asm ├── main.asm ├── out.list └── text.asm ├── 02-Joypad ├── .gitignore ├── README.MD ├── build.sh ├── header.asm ├── joypad.asm ├── main.asm └── sys │ ├── sysDef.asm │ ├── sysInit.asm │ ├── sysMacros.asm │ └── sysRAM.asm ├── 03-VerticalInterrupts ├── .gitignore ├── README.MD ├── build.sh ├── header.68k ├── main.68k ├── sys │ ├── sysDef.68k │ ├── sysInit.68k │ ├── sysInterrupts.68k │ ├── sysJoypad.68k │ ├── sysMacros.68k │ └── sysRAM.68k └── tutorial03.68k ├── 04-PatternsIntro ├── .gitignore ├── 04-Patterns.geany ├── README.MD ├── build.sh ├── header.68k ├── main.68k ├── sys │ ├── sysDef.68k │ ├── sysInit.68k │ ├── sysInterrupts.68k │ ├── sysJoypad.68k │ ├── sysMacros.68k │ └── sysRAM.68k └── tutorial04.68k ├── 05-Fonts ├── .gitignore ├── 05-Fonts.geany ├── README.MD ├── build.sh ├── header.68k ├── main.68k ├── sys │ ├── font │ │ ├── 8x8font.gif │ │ ├── 8x8font.xcf │ │ ├── sys8x8font.png │ │ └── sysFont.68k │ ├── sysDef.68k │ ├── sysInit.68k │ ├── sysInterrupts.68k │ ├── sysJoypad.68k │ ├── sysMacros.68k │ └── sysRAM.68k └── tutorial05.68k ├── 06-StringConversions ├── .gitignore ├── 06-Strings.geany ├── README.MD ├── build.sh ├── header.68k ├── main.68k ├── sys │ ├── font │ │ ├── 8x8font.gif │ │ ├── 8x8font.xcf │ │ ├── sys8x8font.png │ │ └── sysFont.68k │ ├── strings │ │ └── sysStrings.68k │ ├── sysDef.68k │ ├── sysInit.68k │ ├── sysInterrupts.68k │ ├── sysJoypad.68k │ ├── sysMacros.68k │ └── sysRAM.68k └── tutorial06.68k ├── LICENSE ├── README.md ├── filetypes.68k.conf ├── m68kasm.lang └── z80.lang /01-HelloWorld/.gitignore: -------------------------------------------------------------------------------- 1 | *.bin 2 | *.lst 3 | -------------------------------------------------------------------------------- /01-HelloWorld/README.MD: -------------------------------------------------------------------------------- 1 | The hello world tutorial is the project written by Big Evil Corporation (http://bigevilcorporation.co.uk/2012/03/23/sega-megadrive-4-hello-world/). 2 | 3 | I have modified it to compile with ASMX since this assembler can be built on Linux. 4 | 5 | Use build.sh to assemble the ROM - can be re-used for other projects as long as your top-level asm file is named main.asm. Build.sh assumes you have already built ASMX and installed the executable to /usr/local/bin 6 | -------------------------------------------------------------------------------- /01-HelloWorld/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if test -d out 4 | then 5 | echo "cleaning out directory" 6 | rm -r out/* 7 | else 8 | mkdir out 9 | fi 10 | 11 | asmx -C 68000 -e -w -b 0 -l out/rom.lst -o out/rom.bin -- main.asm 12 | -------------------------------------------------------------------------------- /01-HelloWorld/charmap.asm: -------------------------------------------------------------------------------- 1 | ASCIIStart: equ 0x20 ; First ASCII code in table 2 | 3 | ASCIIMap: 4 | dc.b 0x00 ; SPACE (ASCII code 0x20) 5 | dc.b 0x28 ; ! Exclamation mark 6 | dc.b 0x2B ; " Double quotes 7 | dc.b 0x2E ; # Hash 8 | dc.b 0x00 ; UNUSED 9 | dc.b 0x00 ; UNUSED 10 | dc.b 0x00 ; UNUSED 11 | dc.b 0x2C ; ' Single quote 12 | dc.b 0x29 ; ( Open parenthesis 13 | dc.b 0x2A ; ) Close parenthesis 14 | dc.b 0x00 ; UNUSED 15 | dc.b 0x2F ; + Plus 16 | dc.b 0x26 ; , Comma 17 | dc.b 0x30 ; - Minus 18 | dc.b 0x25 ; . Full stop 19 | dc.b 0x31 ; / Slash or divide 20 | dc.b 0x1B ; 0 Zero 21 | dc.b 0x1C ; 1 One 22 | dc.b 0x1D ; 2 Two 23 | dc.b 0x1E ; 3 Three 24 | dc.b 0x1F ; 4 Four 25 | dc.b 0x20 ; 5 Five 26 | dc.b 0x21 ; 6 Six 27 | dc.b 0x22 ; 7 Seven 28 | dc.b 0x23 ; 8 Eight 29 | dc.b 0x24 ; 9 Nine 30 | dc.b 0x2D ; : Colon 31 | dc.b 0x00 ; UNUSED 32 | dc.b 0x00 ; UNUSED 33 | dc.b 0x00 ; UNUSED 34 | dc.b 0x00 ; UNUSED 35 | dc.b 0x27 ; ? Question mark 36 | dc.b 0x00 ; UNUSED 37 | dc.b 0x01 ; A 38 | dc.b 0x02 ; B 39 | dc.b 0x03 ; C 40 | dc.b 0x04 ; D 41 | dc.b 0x05 ; E 42 | dc.b 0x06 ; F 43 | dc.b 0x07 ; G 44 | dc.b 0x08 ; H 45 | dc.b 0x09 ; I 46 | dc.b 0x0A ; J 47 | dc.b 0x0B ; K 48 | dc.b 0x0C ; L 49 | dc.b 0x0D ; M 50 | dc.b 0x0E ; N 51 | dc.b 0x0F ; O 52 | dc.b 0x10 ; P 53 | dc.b 0x11 ; Q 54 | dc.b 0x12 ; R 55 | dc.b 0x13 ; S 56 | dc.b 0x14 ; T 57 | dc.b 0x15 ; U 58 | dc.b 0x16 ; V 59 | dc.b 0x17 ; W 60 | dc.b 0x18 ; X 61 | dc.b 0x19 ; Y 62 | dc.b 0x1A ; Z (ASCII code 0x5A) 63 | -------------------------------------------------------------------------------- /01-HelloWorld/fonts/pixelfont.asm: -------------------------------------------------------------------------------- 1 | ; Align 8 bytes 2 | ALIGN 8 3 | 4 | PixelFont: ; Font start address 5 | 6 | dc.l $00000000 7 | dc.l $00000000 8 | dc.l $00000000 9 | dc.l $00000000 10 | dc.l $00000000 11 | dc.l $00000000 12 | dc.l $00000000 13 | dc.l $00000000 14 | 15 | dc.l $01111100 16 | dc.l $11000110 17 | dc.l $10111010 18 | dc.l $10000010 19 | dc.l $10111010 20 | dc.l $10101010 21 | dc.l $11101110 22 | dc.l $00000000 23 | 24 | dc.l $11111100 25 | dc.l $10000110 26 | dc.l $10111010 27 | dc.l $10000110 28 | dc.l $10111010 29 | dc.l $10000110 30 | dc.l $11111100 31 | dc.l $00000000 32 | 33 | dc.l $01111110 34 | dc.l $11000010 35 | dc.l $10111110 36 | dc.l $10100000 37 | dc.l $10111110 38 | dc.l $11000010 39 | dc.l $01111110 40 | dc.l $00000000 41 | 42 | dc.l $11111100 43 | dc.l $10000110 44 | dc.l $10111010 45 | dc.l $10101010 46 | dc.l $10111010 47 | dc.l $10000110 48 | dc.l $11111100 49 | dc.l $00000000 50 | 51 | dc.l $11111110 52 | dc.l $10000010 53 | dc.l $10111110 54 | dc.l $10001000 55 | dc.l $10111110 56 | dc.l $10000010 57 | dc.l $11111110 58 | dc.l $00000000 59 | 60 | dc.l $11111110 61 | dc.l $10000010 62 | dc.l $10111110 63 | dc.l $10001000 64 | dc.l $10111000 65 | dc.l $10100000 66 | dc.l $11100000 67 | dc.l $00000000 68 | 69 | dc.l $01111110 70 | dc.l $11000010 71 | dc.l $10111110 72 | dc.l $10100010 73 | dc.l $10111010 74 | dc.l $11000010 75 | dc.l $01111110 76 | dc.l $00000000 77 | 78 | dc.l $11101110 79 | dc.l $10101010 80 | dc.l $10111010 81 | dc.l $10000010 82 | dc.l $10111010 83 | dc.l $10101010 84 | dc.l $11101110 85 | dc.l $00000000 86 | 87 | dc.l $11111110 88 | dc.l $10000010 89 | dc.l $11101110 90 | dc.l $00101000 91 | dc.l $11101110 92 | dc.l $10000010 93 | dc.l $11111110 94 | dc.l $00000000 95 | 96 | dc.l $00001110 97 | dc.l $00001010 98 | dc.l $00001010 99 | dc.l $11101010 100 | dc.l $10111010 101 | dc.l $11000110 102 | dc.l $01111100 103 | dc.l $00000000 104 | 105 | dc.l $11101110 106 | dc.l $10111010 107 | dc.l $10110110 108 | dc.l $10001100 109 | dc.l $10110110 110 | dc.l $10111010 111 | dc.l $11101110 112 | dc.l $00000000 113 | 114 | dc.l $11100000 115 | dc.l $10100000 116 | dc.l $10100000 117 | dc.l $10100000 118 | dc.l $10111110 119 | dc.l $10000010 120 | dc.l $11111110 121 | dc.l $00000000 122 | 123 | dc.l $11101110 124 | dc.l $10111010 125 | dc.l $10010010 126 | dc.l $10101010 127 | dc.l $10111010 128 | dc.l $10101010 129 | dc.l $11101110 130 | dc.l $00000000 131 | 132 | dc.l $11101110 133 | dc.l $10111010 134 | dc.l $10011010 135 | dc.l $10101010 136 | dc.l $10110010 137 | dc.l $10111010 138 | dc.l $11101110 139 | dc.l $00000000 140 | 141 | dc.l $01111100 142 | dc.l $11000110 143 | dc.l $10111010 144 | dc.l $10101010 145 | dc.l $10111010 146 | dc.l $11000110 147 | dc.l $01111100 148 | dc.l $00000000 149 | 150 | dc.l $11111100 151 | dc.l $10000110 152 | dc.l $10111010 153 | dc.l $10000110 154 | dc.l $10111100 155 | dc.l $10100000 156 | dc.l $11100000 157 | dc.l $00000000 158 | 159 | dc.l $01111100 160 | dc.l $11000110 161 | dc.l $10111010 162 | dc.l $10101010 163 | dc.l $10110110 164 | dc.l $11001010 165 | dc.l $01111110 166 | dc.l $00000000 167 | 168 | dc.l $11111100 169 | dc.l $10000110 170 | dc.l $10111010 171 | dc.l $10000110 172 | dc.l $10110110 173 | dc.l $10111010 174 | dc.l $11101110 175 | dc.l $00000000 176 | 177 | dc.l $01111110 178 | dc.l $11000010 179 | dc.l $10111110 180 | dc.l $11000110 181 | dc.l $11111010 182 | dc.l $10000110 183 | dc.l $11111100 184 | dc.l $00000000 185 | 186 | dc.l $11111110 187 | dc.l $10000010 188 | dc.l $11101110 189 | dc.l $00101000 190 | dc.l $00101000 191 | dc.l $00101000 192 | dc.l $00111000 193 | dc.l $00000000 194 | 195 | dc.l $11101110 196 | dc.l $10101010 197 | dc.l $10101010 198 | dc.l $10101010 199 | dc.l $10111010 200 | dc.l $11000110 201 | dc.l $01111100 202 | dc.l $00000000 203 | 204 | dc.l $11101110 205 | dc.l $10101010 206 | dc.l $10111010 207 | dc.l $11010110 208 | dc.l $01010100 209 | dc.l $01101100 210 | dc.l $00111000 211 | dc.l $00000000 212 | 213 | dc.l $11101110 214 | dc.l $10101010 215 | dc.l $10111010 216 | dc.l $10101010 217 | dc.l $10010010 218 | dc.l $10111010 219 | dc.l $11101110 220 | dc.l $00000000 221 | 222 | dc.l $11101110 223 | dc.l $10111010 224 | dc.l $11010110 225 | dc.l $01101100 226 | dc.l $11010110 227 | dc.l $10111010 228 | dc.l $11101110 229 | dc.l $00000000 230 | 231 | dc.l $11101110 232 | dc.l $10111010 233 | dc.l $11010110 234 | dc.l $01101100 235 | dc.l $00101000 236 | dc.l $00101000 237 | dc.l $00111000 238 | dc.l $00000000 239 | 240 | dc.l $11111110 241 | dc.l $10000010 242 | dc.l $11110110 243 | dc.l $01101100 244 | dc.l $11011110 245 | dc.l $10000010 246 | dc.l $11111110 247 | dc.l $00000000 248 | 249 | dc.l $01111100 250 | dc.l $11000110 251 | dc.l $10110010 252 | dc.l $10101010 253 | dc.l $10011010 254 | dc.l $11000110 255 | dc.l $01111100 256 | dc.l $00000000 257 | 258 | dc.l $01111000 259 | dc.l $01001000 260 | dc.l $01101000 261 | dc.l $00101000 262 | dc.l $01101100 263 | dc.l $01000100 264 | dc.l $01111100 265 | dc.l $00000000 266 | 267 | dc.l $11111100 268 | dc.l $10000110 269 | dc.l $11111010 270 | dc.l $11000110 271 | dc.l $10111110 272 | dc.l $10000010 273 | dc.l $11111110 274 | dc.l $00000000 275 | 276 | dc.l $11111100 277 | dc.l $10000110 278 | dc.l $11111010 279 | dc.l $00100110 280 | dc.l $11111010 281 | dc.l $10000110 282 | dc.l $11111100 283 | dc.l $00000000 284 | 285 | dc.l $11101110 286 | dc.l $10101010 287 | dc.l $10111010 288 | dc.l $10000010 289 | dc.l $11111010 290 | dc.l $00001010 291 | dc.l $00001110 292 | dc.l $00000000 293 | 294 | dc.l $11111110 295 | dc.l $10000010 296 | dc.l $10111110 297 | dc.l $10000110 298 | dc.l $11111010 299 | dc.l $10000110 300 | dc.l $11111100 301 | dc.l $00000000 302 | 303 | dc.l $01111100 304 | dc.l $11000100 305 | dc.l $10111100 306 | dc.l $10000110 307 | dc.l $10111010 308 | dc.l $11000110 309 | dc.l $01111100 310 | dc.l $00000000 311 | 312 | dc.l $11111110 313 | dc.l $10000010 314 | dc.l $11111010 315 | dc.l $00110110 316 | dc.l $01101100 317 | dc.l $01011000 318 | dc.l $01110000 319 | dc.l $00000000 320 | 321 | dc.l $01111100 322 | dc.l $11000110 323 | dc.l $10111010 324 | dc.l $11000110 325 | dc.l $10111010 326 | dc.l $11000110 327 | dc.l $01111100 328 | dc.l $00000000 329 | 330 | dc.l $01111100 331 | dc.l $11000110 332 | dc.l $10111010 333 | dc.l $11000010 334 | dc.l $01111010 335 | dc.l $01000110 336 | dc.l $01111100 337 | dc.l $00000000 338 | 339 | dc.l $00000000 340 | dc.l $00000000 341 | dc.l $00000000 342 | dc.l $00000000 343 | dc.l $00000000 344 | dc.l $11000000 345 | dc.l $11000000 346 | dc.l $00000000 347 | 348 | dc.l $00000000 349 | dc.l $00000000 350 | dc.l $00000000 351 | dc.l $00000000 352 | dc.l $11100000 353 | dc.l $10100000 354 | dc.l $10100000 355 | dc.l $11100000 356 | 357 | dc.l $01111100 358 | dc.l $11000110 359 | dc.l $10111010 360 | dc.l $11100110 361 | dc.l $00111100 362 | dc.l $00101000 363 | dc.l $00111000 364 | dc.l $00000000 365 | 366 | dc.l $11100000 367 | dc.l $10100000 368 | dc.l $10100000 369 | dc.l $10100000 370 | dc.l $11100000 371 | dc.l $10100000 372 | dc.l $11100000 373 | dc.l $00000000 374 | 375 | dc.l $01110000 376 | dc.l $11010000 377 | dc.l $10110000 378 | dc.l $10100000 379 | dc.l $10110000 380 | dc.l $11010000 381 | dc.l $01110000 382 | dc.l $00000000 383 | 384 | dc.l $11100000 385 | dc.l $10110000 386 | dc.l $11010000 387 | dc.l $01010000 388 | dc.l $11010000 389 | dc.l $10110000 390 | dc.l $11100000 391 | dc.l $00000000 392 | 393 | dc.l $11111000 394 | dc.l $10101000 395 | dc.l $10101000 396 | dc.l $11111000 397 | dc.l $00000000 398 | dc.l $00000000 399 | dc.l $00000000 400 | dc.l $00000000 401 | 402 | dc.l $11100000 403 | dc.l $10100000 404 | dc.l $10100000 405 | dc.l $11100000 406 | dc.l $00000000 407 | dc.l $00000000 408 | dc.l $00000000 409 | dc.l $00000000 410 | 411 | dc.l $00000000 412 | dc.l $11100000 413 | dc.l $10100000 414 | dc.l $11100000 415 | dc.l $10100000 416 | dc.l $11100000 417 | dc.l $00000000 418 | dc.l $00000000 419 | 420 | dc.l $01111100 421 | dc.l $11010110 422 | dc.l $10000010 423 | dc.l $11010110 424 | dc.l $10000010 425 | dc.l $11010110 426 | dc.l $01111100 427 | dc.l $00000000 428 | 429 | dc.l $00111000 430 | dc.l $00101000 431 | dc.l $11101110 432 | dc.l $10000010 433 | dc.l $11101110 434 | dc.l $00101000 435 | dc.l $00111000 436 | dc.l $00000000 437 | 438 | dc.l $00000000 439 | dc.l $00000000 440 | dc.l $11111110 441 | dc.l $10000010 442 | dc.l $11111110 443 | dc.l $00000000 444 | dc.l $00000000 445 | dc.l $00000000 446 | 447 | dc.l $00011100 448 | dc.l $00110100 449 | dc.l $01101100 450 | dc.l $11011000 451 | dc.l $10110000 452 | dc.l $11100000 453 | dc.l $00000000 454 | dc.l $00000000 455 | 456 | PixelFontEnd ; Font end address 457 | PixelFontSizeB: equ (PixelFontEnd-PixelFont) ; Font size in bytes 458 | PixelFontSizeW: equ (PixelFontSizeB/2) ; Font size in words 459 | PixelFontSizeL: equ (PixelFontSizeB/4) ; Font size in longs 460 | PixelFontSizeT: equ (PixelFontSizeB/32) ; Font size in tiles 461 | PixelFontVRAM: equ 0x0100 ; Dest address in VRAM 462 | PixelFontTileID: equ (PixelFontVRAM/32) ; ID of first tile 463 | -------------------------------------------------------------------------------- /01-HelloWorld/globals.asm: -------------------------------------------------------------------------------- 1 | vdp_control equ 0x00C00004 2 | vdp_data equ 0x00C00000 3 | 4 | vdp_write_palettes equ 0xF0000000 5 | vdp_write_tiles equ 0x40000000 6 | vdp_write_plane_a equ 0x40000003 7 | vdp_write_sprite_tiles equ 0x60000000 8 | vdp_write_sprite_table equ 0x60000003 -------------------------------------------------------------------------------- /01-HelloWorld/main.asm: -------------------------------------------------------------------------------- 1 | include 'init.asm' 2 | include 'globals.asm' 3 | include 'text.asm' 4 | 5 | __main: 6 | 7 | move.w #0x8F02, vdp_control ; Set autoincrement to 2 bytes 8 | 9 | ; ************************************ 10 | ; Move palettes to CRAM 11 | ; ************************************ 12 | move.l #vdp_write_palettes, vdp_control ; Set up VDP to write to CRAM address 0x0000 13 | 14 | lea Palettes, a0 ; Load address of Palettes into a0 15 | move.l #0x1F, d0 ; 128 bytes of data (4 palettes, 32 longwords, minus 1 for counter) in palettes 16 | 17 | .ColourLoop: 18 | move.l (a0)+, vdp_data ; Move data to VDP data port, and increment source address 19 | dbra d0, .ColourLoop 20 | 21 | ; ************************************ 22 | ; Load font 23 | ; ************************************ 24 | lea PixelFont, a0 ; Move font address to a0 25 | move.l #PixelFontVRAM, d0 ; Move VRAM dest address to d0 26 | move.l #PixelFontSizeT, d1 ; Move number of characters (font size in tiles) to d1 27 | jsr LoadFont ; Jump to subroutine 28 | 29 | ; ************************************ 30 | ; Draw text 31 | ; ************************************ 32 | lea String1, a0 ; String address 33 | move.l #PixelFontTileID, d0 ; First tile id 34 | move.w #0x0501, d1 ; XY (5, 1) 35 | move.l #0x0, d2 ; Palette 0 36 | jsr DrawTextPlaneA ; Call draw text subroutine 37 | 38 | lea String2, a0 ; String address 39 | move.l #PixelFontTileID, d0 ; First tile id 40 | move.w #0x0502, d1 ; XY (5, 2) 41 | move.l #0x1, d2 ; Palette 1 42 | jsr DrawTextPlaneA ; Call draw text subroutine 43 | 44 | lea String3, a0 ; String address 45 | move.l #PixelFontTileID, d0 ; First tile id 46 | move.w #0x0503, d1 ; XY (5, 3) 47 | move.l #0x2, d2 ; Palette 2 48 | jsr DrawTextPlaneA ; Call draw text subroutine 49 | 50 | lea String4, a0 ; String address 51 | move.l #PixelFontTileID, d0 ; First tile id 52 | move.w #0x0504, d1 ; XY (5, 4) 53 | move.l #0x3, d2 ; Palette 3 54 | jsr DrawTextPlaneA ; Call draw text subroutine 55 | 56 | lea String5, a0 ; String address 57 | move.l #PixelFontTileID, d0 ; First tile id 58 | move.w #0x0106, d1 ; XY (1, 6) 59 | move.l #0x3, d2 ; Palette 3 60 | jsr DrawTextPlaneA ; Call draw text subroutine 61 | 62 | lea String6, a0 ; String address 63 | move.l #PixelFontTileID, d0 ; First tile id 64 | move.w #0x0107, d1 ; XY (1, 7) 65 | move.l #0x3, d2 ; Palette 3 66 | jsr DrawTextPlaneA ; Call draw text subroutine 67 | 68 | stop #$2700 ; Halt CPU 69 | 70 | Palettes: 71 | dc.w 0x0000 ; Colour 0 - Transparent 72 | dc.w 0x000E ; Colour 1 - Red 73 | dc.w 0x0000 74 | dc.w 0x0000 75 | dc.w 0x0000 76 | dc.w 0x0000 77 | dc.w 0x0000 78 | dc.w 0x0000 79 | dc.w 0x0000 80 | dc.w 0x0000 81 | dc.w 0x0000 82 | dc.w 0x0000 83 | dc.w 0x0000 84 | dc.w 0x0000 85 | dc.w 0x0000 86 | dc.w 0x0000 87 | 88 | dc.w 0x0000 ; Colour 0 - Transparent 89 | dc.w 0x00E0 ; Colour 1 - Green 90 | dc.w 0x0000 91 | dc.w 0x0000 92 | dc.w 0x0000 93 | dc.w 0x0000 94 | dc.w 0x0000 95 | dc.w 0x0000 96 | dc.w 0x0000 97 | dc.w 0x0000 98 | dc.w 0x0000 99 | dc.w 0x0000 100 | dc.w 0x0000 101 | dc.w 0x0000 102 | dc.w 0x0000 103 | dc.w 0x0000 104 | 105 | dc.w 0x0000 ; Colour 0 - Transparent 106 | dc.w 0x0E00 ; Colour 1 - Blue 107 | dc.w 0x0000 108 | dc.w 0x0000 109 | dc.w 0x0000 110 | dc.w 0x0000 111 | dc.w 0x0000 112 | dc.w 0x0000 113 | dc.w 0x0000 114 | dc.w 0x0000 115 | dc.w 0x0000 116 | dc.w 0x0000 117 | dc.w 0x0000 118 | dc.w 0x0000 119 | dc.w 0x0000 120 | dc.w 0x0000 121 | 122 | dc.w 0x0000 ; Colour 0 - Transparent 123 | dc.w 0x0EEE ; Colour 1 - White 124 | dc.w 0x0000 125 | dc.w 0x0000 126 | dc.w 0x0000 127 | dc.w 0x0000 128 | dc.w 0x0000 129 | dc.w 0x0000 130 | dc.w 0x0000 131 | dc.w 0x0000 132 | dc.w 0x0000 133 | dc.w 0x0000 134 | dc.w 0x0000 135 | dc.w 0x0000 136 | dc.w 0x0000 137 | dc.w 0x0000 138 | 139 | ; Text strings (zero terminated) 140 | String1: 141 | dc.b "ABCDEFGHIJKLM",0 142 | String2: 143 | dc.b "NOPQRSTUVWXYZ",0 144 | String3: 145 | dc.b "0123456789",0 146 | String4: 147 | dc.b ",.?!()""':#+-/",0 148 | String5: 149 | dc.b "THE QUICK BROWN FOX JUMPS",0 150 | String6: 151 | dc.b "OVER THE LAZY DOG",0 152 | 153 | ; Include art assets 154 | include 'fonts/pixelfont.asm' 155 | 156 | __end ; Very last line, end of ROM address 157 | -------------------------------------------------------------------------------- /01-HelloWorld/text.asm: -------------------------------------------------------------------------------- 1 | include 'charmap.asm' 2 | 3 | ; Align 8 bytes 4 | ALIGN 8 5 | 6 | LoadFont: 7 | ; a0 - Font address (l) 8 | ; d0 - VRAM address (w) 9 | ; d1 - Num chars (w) 10 | 11 | swap d0 ; Shift VRAM addr to upper word 12 | add.l #vdp_write_tiles, d0 ; VRAM write cmd + VRAM destination address 13 | move.l d0, vdp_control ; Send address to VDP cmd port 14 | 15 | subq.b #0x1, d1 ; Num chars - 1 16 | .CharCopy: 17 | move.w #0x07, d2 ; 8 longwords in tile 18 | .LongCopy: 19 | move.l (a0)+, vdp_data ; Copy one line of tile to VDP data port 20 | dbra d2, .LongCopy 21 | dbra d1, .CharCopy 22 | 23 | rts 24 | 25 | DrawTextPlaneA: 26 | ; a0 (l) - String address 27 | ; d0 (w) - First tile ID of font 28 | ; d1 (bb)- XY coord (in tiles) 29 | ; d2 (b) - Palette 30 | 31 | clr.l d3 ; Clear d3 ready to work with 32 | move.b d1, d3 ; Move Y coord (lower byte of d1) to d3 33 | mulu.w #0x0040, d3 ; Multiply Y by line width (H40 mode - 64 lines horizontally) to get Y offset 34 | ror.l #0x8, d1 ; Shift X coord from upper to lower byte of d1 35 | add.b d1, d3 ; Add X coord to offset 36 | mulu.w #0x2, d3 ; Convert to words 37 | swap d3 ; Shift address offset to upper word 38 | add.l #vdp_write_plane_a, d3 ; Add PlaneA write cmd + address 39 | move.l d3, vdp_control ; Send to VDP control port 40 | 41 | clr.l d3 ; Clear d3 ready to work with again 42 | move.b d2, d3 ; Move palette ID (lower byte of d2) to d3 43 | rol.l #0x8, d3 ; Shift palette ID to bits 14 and 15 of d3 44 | rol.l #0x5, d3 ; Can only rol bits up to 8 places in one instruction 45 | 46 | lea ASCIIMap, a1 ; Load address of ASCII map into a1 47 | 48 | .CharCopy: 49 | move.b (a0)+, d2 ; Move ASCII byte to lower byte of d2 50 | cmp.b #0x0, d2 ; Test if byte is zero (string terminator) 51 | beq.b .Done ; If byte was zero, branch to end 52 | 53 | sub.b #ASCIIStart, d2 ; Subtract first ASCII code to get table entry index 54 | move.b (a1,d2.w), d3 ; Move tile ID from table (index in lower word of d2) to lower byte of d3 55 | add.w d0, d3 ; Offset tile ID by first tile ID in font 56 | move.w d3, vdp_data ; Move palette and pattern IDs to VDP data port 57 | jmp .CharCopy ; Next character 58 | 59 | .Done: 60 | rts 61 | -------------------------------------------------------------------------------- /02-Joypad/.gitignore: -------------------------------------------------------------------------------- 1 | *.bin 2 | *.lst 3 | -------------------------------------------------------------------------------- /02-Joypad/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if test -d out 4 | then 5 | echo "cleaning out directory" 6 | rm -r out/* 7 | else 8 | mkdir out 9 | fi 10 | 11 | asmx -C 68000 -e -w -b 0 -l out/rom.lst -o out/rom.bin -- main.asm 12 | -------------------------------------------------------------------------------- /02-Joypad/header.asm: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; Sega Megadrive ROM header 3 | ; ****************************************************************** 4 | dc.l $00FFE000 ; Initial stack pointer value 5 | dc.l EntryPoint ; Start of program 6 | dc.l Exception ; Bus error 7 | dc.l Exception ; Address error 8 | dc.l Exception ; Illegal instruction 9 | dc.l Exception ; Division by zero 10 | dc.l Exception ; CHK exception 11 | dc.l Exception ; TRAPV exception 12 | dc.l Exception ; Privilege violation 13 | dc.l Exception ; TRACE exception 14 | dc.l Exception ; Line-A emulator 15 | dc.l Exception ; Line-F emulator 16 | dc.l Exception ; Unused (reserved) 17 | dc.l Exception ; Unused (reserved) 18 | dc.l Exception ; Unused (reserved) 19 | dc.l Exception ; Unused (reserved) 20 | dc.l Exception ; Unused (reserved) 21 | dc.l Exception ; Unused (reserved) 22 | dc.l Exception ; Unused (reserved) 23 | dc.l Exception ; Unused (reserved) 24 | dc.l Exception ; Unused (reserved) 25 | dc.l Exception ; Unused (reserved) 26 | dc.l Exception ; Unused (reserved) 27 | dc.l Exception ; Unused (reserved) 28 | dc.l Exception ; Spurious exception 29 | dc.l Exception ; IRQ level 1 30 | dc.l Exception ; IRQ level 2 31 | dc.l Exception ; IRQ level 3 32 | dc.l HBlankInterrupt ; IRQ level 4 (horizontal retrace interrupt) 33 | dc.l Exception ; IRQ level 5 34 | dc.l VBlankInterrupt ; IRQ level 6 (vertical retrace interrupt) 35 | dc.l Exception ; IRQ level 7 36 | dc.l Exception ; TRAP #00 exception 37 | dc.l Exception ; TRAP #01 exception 38 | dc.l Exception ; TRAP #02 exception 39 | dc.l Exception ; TRAP #03 exception 40 | dc.l Exception ; TRAP #04 exception 41 | dc.l Exception ; TRAP #05 exception 42 | dc.l Exception ; TRAP #06 exception 43 | dc.l Exception ; TRAP #07 exception 44 | dc.l Exception ; TRAP #08 exception 45 | dc.l Exception ; TRAP #09 exception 46 | dc.l Exception ; TRAP #10 exception 47 | dc.l Exception ; TRAP #11 exception 48 | dc.l Exception ; TRAP #12 exception 49 | dc.l Exception ; TRAP #13 exception 50 | dc.l Exception ; TRAP #14 exception 51 | dc.l Exception ; TRAP #15 exception 52 | dc.l Exception ; Unused (reserved) 53 | dc.l Exception ; Unused (reserved) 54 | dc.l Exception ; Unused (reserved) 55 | dc.l Exception ; Unused (reserved) 56 | dc.l Exception ; Unused (reserved) 57 | dc.l Exception ; Unused (reserved) 58 | dc.l Exception ; Unused (reserved) 59 | dc.l Exception ; Unused (reserved) 60 | dc.l Exception ; Unused (reserved) 61 | dc.l Exception ; Unused (reserved) 62 | dc.l Exception ; Unused (reserved) 63 | dc.l Exception ; Unused (reserved) 64 | dc.l Exception ; Unused (reserved) 65 | dc.l Exception ; Unused (reserved) 66 | dc.l Exception ; Unused (reserved) 67 | dc.l Exception ; Unused (reserved) 68 | 69 | ; size 012345678901234567890123456789012345678901234567 70 | dc.b "SEGA GENESIS " ; Console name - 16 71 | dc.b "(C)db 2016.MAR" ; Copyright holder and release date - 16 72 | dc.b "DB JOYPAD TUTORIAL " ; Domestic name - 48 73 | dc.b "DB JOYPAD TUTORIAL " ; International name - 48 74 | dc.b "GM JPTUTORL-01" ; Version number - 48 75 | dc.w $1234 ; Checksum 76 | dc.b "J " ; I/O support - 16 77 | dc.l $00000000 ; Start address of ROM 78 | dc.l __end ; End address of ROM 79 | dc.l $00FF0000 ; Start address of RAM 80 | dc.l $00FFFFFF ; End address of RAM 81 | dc.l $00000000 ; SRAM enabled 82 | dc.l $00000000 ; Unused 83 | dc.l $00000000 ; Start address of SRAM 84 | dc.l $00000000 ; End address of SRAM 85 | dc.l $00000000 ; Unused 86 | dc.l $00000000 ; Unused 87 | dc.b " " ; Notes (unused) 88 | dc.b "JUE " ; Country codes 89 | -------------------------------------------------------------------------------- /02-Joypad/joypad.asm: -------------------------------------------------------------------------------- 1 | ; ************************************ 2 | ; Main Entry 3 | ; ************************************ 4 | .loop 5 | WaitVBlankStart_m ; synchronize 6 | WaitVBlankEnd_m 7 | jsr JOYPAD_ReadPad01 ; read joypad state 8 | bra.s .loop 9 | 10 | ; ************************************ 11 | ; JOYPAD_ReadPad01: 12 | ; 13 | ; destroys: 14 | ; A0, A1, D5, D6 15 | ; returns: 16 | ; D6 = SACBRLDU 17 | ; joy1State (RAM) = D6 18 | ; ************************************ 19 | JOYPAD_ReadPad01: 20 | move.l #IO_DATA_1, A0 ; load data_1 address 21 | move.l #joy1State, A1 ; point to RAM placeholder for joystate 22 | move.b (A0), D6 ; read status j1 = 00CBRLDU 23 | move.b #$00, (A0) ; set TH low 24 | nop ; wait to settle 25 | move.b (A0), D5 ; read status = 00SA00DU 26 | rol.b #2, D5 ; SA00DU?? 27 | andi.b #$C0, D5 ; SA000000 28 | or.b D5, D6 ; D6 = SACBRLDU 29 | move.b #$40, (A0) ; set TH high for next pass 30 | move.w D6, (A1) ; store to RAM 31 | rts 32 | 33 | ; ************************************ 34 | ; JOYPAD_READ12 35 | ; 36 | ; destroys: 37 | ; A0, D5, D6 38 | ; returns: 39 | ; j2 j1 40 | ; D6 = xxxxxxxx SACBRLDU xxxxxxxx SACBRLDU 41 | ; ************************************ 42 | JOYPAD_READ12: 43 | move.l #IO_DATA_2, A0 ; load data_2 address 44 | move.l #joy1State, A1 ; point to RAM placeholder for joystate 45 | move.b (A0), D6 ; read status j2 = 00CBRLDU 46 | move.b #$00, (A0) ; set TH low 47 | nop ; wait to settle 48 | move.b (A0), D5 ; read status = 00SA00DU 49 | rol.b #2, D5 ; SA00DU?? 50 | andi.b #$C0, D5 ; SA000000 51 | or.b D5, D6 ; D6.b = SACBRLDU j2 52 | swap D6 ; move j2 to high word in D6 53 | subq.l #IO_DATA_2-IO_DATA_1, A0; load data_2 address 54 | move.b #$40, (A0) ; set TH high for next pass 55 | move.b (A0), D6 ; read status j1 = 00CBRLDU 56 | move.b #$00, (A0) ; set TH low 57 | nop ; wait to settle 58 | move.b (A0), D5 ; read status = 00SA00DU 59 | rol.b #2, D5 ; SA00DU?? 60 | andi.b #$C0, D5 ; SA000000 61 | or.b D5, D6 ; D6.b = SACBRLDU j1 62 | move.b #$40, (A0) ; set TH high for next pass 63 | move.l D6, (A1) ; store to RAM 64 | rts 65 | -------------------------------------------------------------------------------- /02-Joypad/main.asm: -------------------------------------------------------------------------------- 1 | ; ************************************ 2 | ; COMPILER OPTIONS 3 | ; ************************************ 4 | LIST MACRO 5 | LIST NOSYM 6 | LIST NOTEMP 7 | 8 | ; ************************************ 9 | ; SYSTEM DEFINES 10 | ; ************************************ 11 | include 'sys/sysDef.asm' 12 | include 'sys/sysRAM.asm' 13 | 14 | ; ************************************ 15 | ; MACROS 16 | ; ************************************ 17 | include 'sys/sysMacros.asm' 18 | 19 | ; ************************************ 20 | ; HEADER AND STARTUP CODE 21 | ; ************************************ 22 | include 'header.asm' 23 | include 'sys/sysInit.asm' 24 | 25 | ; ************************************ 26 | ; USER PROGRAM 27 | ; ************************************ 28 | __main: 29 | include 'joypad.asm' 30 | __end: 31 | 32 | ; debug in MESS using 33 | ; mess genesis -cart out/rom.bin -window -debug 34 | -------------------------------------------------------------------------------- /02-Joypad/sys/sysDef.asm: -------------------------------------------------------------------------------- 1 | ; ************************************ 2 | ; VDP Addresses 3 | ; ************************************ 4 | VDP_DATA equ $00C00000 5 | VDP_CTRL equ $00C00004 6 | VDP_HVCOUNTER equ $00C00008 7 | VDP_PSG equ $00C00011 8 | 9 | ; VDP Control Masks 10 | VDP_VSRAM_WRITE equ $40000010 11 | VDP_VSRAM_READ equ $00000010 12 | VDP_CRAM_WRITE equ $C0000000 13 | VDP_CRAM_READ equ $00000020 14 | VDP_VRAM_WRITE equ $40000000 15 | VDP_VRAM_READ equ $00000000 16 | 17 | ; ************************************ 18 | ; I/O Addresses 19 | ; ************************************ 20 | IO_VERSIONNO equ $00A10001 21 | IO_DATA_1 equ $00A10003 22 | IO_DATA_2 equ $00A10005 23 | IO_DATA_EXP equ $00A10007 24 | IO_CTRL_1 equ $00A10009 25 | IO_CTRL_2 equ $00A1000B 26 | IO_CTRL_EXP equ $00A1000D 27 | IO_TXDATA_1 equ $00A1000F 28 | IO_RXDATA_1 equ $00A10011 29 | IO_SCTRL_1 equ $00A10013 30 | IO_TXDATA_2 equ $00A10015 31 | IO_RXDATA_2 equ $00A10017 32 | IO_SCTRL_2 equ $00A10019 33 | IO_TXDATA_3 equ $00A1001B 34 | IO_RXDATA_3 equ $00A1001D 35 | IO_SCTRL_EXP equ $00A1001F 36 | 37 | ; ************************************ 38 | ; Z80 Addresses 39 | ; ************************************ 40 | Z80_MEMSPACE equ $00A00000 41 | Z80_RAM equ $00A00000 42 | 43 | ; ************************************ 44 | ; CTRL Addresses 45 | ; ************************************ 46 | CTRL_MEMMODE equ $00A11000 47 | CTRL_Z80BUSREQ equ $00A11100 48 | CTRL_Z80RESET equ $00A11200 49 | CTRL_TIME equ $00A13000 50 | CTRL_TMSS equ $00A14000 51 | 52 | ; ************************************ 53 | ; Other Addresses 54 | ; ************************************ 55 | M68K_RAM equ $00FF0000 56 | 57 | ; ************************************ 58 | ; JOY bit numbers SACBRLDU 59 | ; ************************************ 60 | JOY_UP equ 0 61 | JOY_DOWN equ 1 62 | JOY_LEFT equ 2 63 | JOY_RIGHT equ 3 64 | JOY_A equ 6 65 | JOY_B equ 4 66 | JOY_C equ 5 67 | JOY_START equ 7 68 | -------------------------------------------------------------------------------- /02-Joypad/sys/sysInit.asm: -------------------------------------------------------------------------------- 1 | 2 | ORG $00000200 ; header section should get us to $200 3 | ; but ORG in case we made a mistake (ASMX will complain) 4 | EntryPoint: ; Entry point address set in ROM header 5 | 6 | ; ************************************ 7 | ; Test reset button 8 | ; ************************************ 9 | tst.w $00A10008 ; Test mystery reset (expansion port reset?) 10 | bne.w Main ; Branch if Not Equal (to zero) - to Main 11 | tst.w $00A1000C ; Test reset button 12 | bne.w Main ; Branch if Not Equal (to zero) - to Main 13 | 14 | ; ************************************ 15 | ; Clear RAM 16 | ; ************************************ 17 | clr.l D0 ; Place a 0 into d0, ready to copy to each longword of RAM 18 | move.l M68K_RAM, A0 ; A0 points to beginning of RAM 19 | move.l #$00004000, D1 ; Clearing 64k's worth of longwords 20 | .Clear: 21 | move.l D0, (A0)+ ; Post-inc faster than Pre-dec (as last tutorial) 22 | dbra D1, .Clear ; Decrement d0, repeat until depleted 23 | 24 | ; ************************************ 25 | ; Write TMSS 26 | ; ************************************ 27 | move.b IO_VERSIONNO, D0 ; Move Megadrive hardware version to d0 28 | andi.b #$0F, D0 ; The version is stored in last four bits, so mask it with 0F 29 | beq.s .SkipTMSS ; If version is equal to 0, skip TMSS signature 30 | move.l #'SEGA', CTRL_TMSS ; Move the string "SEGA" to $A14000 31 | .SkipTMSS: 32 | 33 | ; ************************************ 34 | ; Init Z80 35 | ; ************************************ 36 | Z80Reset_m 37 | Z80Request_m 38 | 39 | ; clear the Z80's 8KB of RAM 40 | move.w #$2000, D0 ; 8KB of Z80 RAM to clear 41 | move.l #Z80_RAM, A1 ; A1 points to Z80 RAM 42 | .ClearZ80 43 | clr.b (A1)+ ; clear bytes, $00 is Z80 nop 44 | dbra D0, .ClearZ80 45 | 46 | ; load simple program to Z80 47 | move.l #Z80Data, A0 ; Load address of data into a0 48 | move.l #Z80_RAM, A1 ; Copy Z80 RAM address to a1 49 | move.l #Z80DataEnd-Z80Data, D0 ; Auto-calculate size of transfer using labels 50 | .CopyZ80: 51 | move.b (A0)+, (A1)+ ; Copy data, and increment the source/dest addresses 52 | dbra D0, .CopyZ80 53 | 54 | Z80Reset_m 55 | Z80Release_m 56 | 57 | ; ************************************ 58 | ; Init PSG 59 | ; ************************************ 60 | move.b $9F, VDP_PSG ; mutes all PSG channels 61 | move.b $BF, VDP_PSG 62 | move.b $DF, VDP_PSG 63 | move.b $FF, VDP_PSG 64 | 65 | ; ************************************ 66 | ; Init VDP 67 | ; DO - iterations 68 | ; D1.uw - register number in VDP 69 | ; D1.lw - register value 70 | ; A0 - pointer to VDP register value array 71 | ; ************************************ 72 | move.l #VDPRegisters, A0 ; Load address of register table into a0 73 | move.l #24, D0 ; 24 registers to write 74 | move.l #$00008000, d1 ; 'Set register 0' command (and clear the rest of d1 ready) 75 | 76 | .CopyVDP: 77 | move.b (A0)+, D1 ; Move register value to lower byte of d1 78 | move.w D1, VDP_CTRL ; Write command and value to VDP control port 79 | add.w #$0100, D1 ; Increment register # 80 | dbra D0, .CopyVDP 81 | 82 | ; ************************************ 83 | ; Init IO Ports 84 | ; ************************************ 85 | move.b #$40, IO_CTRL_1 ; Controller port 1 CTRL, TH = output 86 | move.b #$40, IO_CTRL_2 ; Controller port 2 CTRL, TH = output 87 | move.b #$00, IO_CTRL_EXP ; EXP port CTRL 88 | move.b #$40, IO_DATA_1 ; Idle with TH = '1' 89 | move.b #$40, IO_DATA_2 ; Idle with TH = '1' 90 | 91 | ; ************************************ 92 | ; Cleanup 93 | ; ************************************ 94 | move.l #M68K_RAM, A0 ; A0 points to $00 value in RAM (has been cleared) 95 | movem.l (A0), D0-D7/A1-A6 ; Multiple move zero to all registers 96 | suba.l A0, A0 ; Clear A0 97 | 98 | ; Init status register (no trace, supervisor mode, all interrupt levels enabled, clear condition code bits) 99 | move #$2000, SR 100 | 101 | ; ************************************ 102 | ; Main 103 | ; ************************************ 104 | Main: 105 | jmp __main ; Begin external main 106 | 107 | HBlankInterrupt: 108 | rte 109 | 110 | VBlankInterrupt: 111 | addq.l #1, vintcounter ; increment vint counter 112 | rte 113 | 114 | Exception: 115 | stop #$2700 ; Halt CPU 116 | 117 | Z80Data: 118 | dc.w $af01, $d91f 119 | dc.w $1127, $0021 120 | dc.w $2600, $f977 121 | dc.w $edb0, $dde1 122 | dc.w $fde1, $ed47 123 | dc.w $ed4f, $d1e1 124 | dc.w $f108, $d9c1 125 | dc.w $d1e1, $f1f9 126 | dc.w $f3ed, $5636 127 | dc.w $e9e9, $8104 128 | dc.w $8f01 129 | Z80DataEnd: 130 | 131 | VDPRegisters: 132 | dc.b $04 ; 0: Horiz. interrupt off, display on 133 | dc.b $74 ; 1: Vert. interrupt on, screen blank off, DMA on, V28 mode (40 cells vertically), Genesis mode on 134 | dc.b $30 ; 2: Pattern table for Scroll Plane A at $C000 (bits 3-5) 135 | dc.b $40 ; 3: Pattern table for Window Plane at $10000 (bits 1-5) 136 | dc.b $05 ; 4: Pattern table for Scroll Plane B at $A000 (bits 0-2) 137 | dc.b $70 ; 5: Sprite table at $E000 (bits 0-6) 138 | dc.b $00 ; 6: Unused 139 | dc.b $00 ; 7: Background colour - bits 0-3 = colour, bits 4-5 = palette 140 | dc.b $00 ; 8: Unused 141 | dc.b $00 ; 9: Unused 142 | dc.b $00 ; 10: Frequency of Horiz. interrupt in Rasters (number of lines travelled by the beam) 143 | dc.b $00 ; 11: External interrupts off, V/H scrolling on 144 | dc.b $81 ; 12: Shadows and highlights off, interlace off, H40 mode (64 cells horizontally) 145 | dc.b $34 ; 13: Horiz. scroll table at $D000 (bits 0-5) 146 | dc.b $00 ; 14: Unused 147 | dc.b $00 ; 15: Autoincrement off 148 | dc.b $01 ; 16: Vert. scroll 32, Horiz. scroll 64 149 | dc.b $00 ; 17: Window Plane X pos 0 left (pos in bits 0-4, left/right in bit 7) 150 | dc.b $00 ; 18: Window Plane Y pos 0 up (pos in bits 0-4, up/down in bit 7) 151 | dc.b $00 ; 19: DMA length lo byte 152 | dc.b $00 ; 20: DMA length hi byte 153 | dc.b $00 ; 21: DMA source address lo byte 154 | dc.b $00 ; 22: DMA source address mid byte 155 | dc.b $00 ; 23: DMA source address hi byte, memory-to-VRAM mode (bits 6-7) 156 | VDPRegistersEnd: 157 | -------------------------------------------------------------------------------- /02-Joypad/sys/sysMacros.asm: -------------------------------------------------------------------------------- 1 | ; ************************************ 2 | ; MACROS 3 | ; ************************************ 4 | Z80Reset_m MACRO 5 | move.w #$0000, CTRL_Z80RESET 6 | exg.l A0,A1 ; waste some time 7 | exg.l A1,A0 8 | move.w #$0100, CTRL_Z80RESET 9 | ENDM 10 | 11 | Z80Request_m MACRO 12 | move.w #$0100, CTRL_Z80BUSREQ 13 | .\?Wait 14 | btst.b #0, CTRL_Z80BUSREQ 15 | bne.s .\?Wait 16 | ENDM 17 | 18 | Z80Release_m MACRO 19 | move.w #$0000, CTRL_Z80BUSREQ 20 | ENDM 21 | 22 | WaitVBlankStart_m MACRO 23 | .\?Wait 24 | move.w VDP_CTRL, D0 ; Move VDP status word to d0 25 | andi.w #$0008, D0 ; AND with bit 4 (vblank), result in status register 26 | bne.s .\?Wait ; Branch if not equal (to zero) 27 | ENDM 28 | 29 | WaitVBlankEnd_m MACRO 30 | .\?Wait 31 | move.w VDP_CTRL, D0 ; Move VDP status word to d0 32 | andi.w #$0008, D0 ; AND with bit 4 (vblank), result in status register 33 | beq.s .\?Wait ; Branch if equal (to zero) 34 | ENDM 35 | -------------------------------------------------------------------------------- /02-Joypad/sys/sysRAM.asm: -------------------------------------------------------------------------------- 1 | ; ************************************ 2 | ; Soft Interrupt Vectors 3 | ; ************************************ 4 | _RAMVECTORSBASE EQU $00FF0000 5 | vintvector EQU _RAMVECTORSBASE+0 6 | hintvector EQU _RAMVECTORSBASE+4 7 | xintvector EQU _RAMVECTORSBASE+8 8 | vintcounter EQU _RAMVECTORSBASE+12 9 | 10 | ; ************************************ 11 | ; Joypads 12 | ; ************************************ 13 | _RAMJOYSTATEBASE EQU $00FF0010 14 | joy1state EQU _RAMJOYSTATEBASE+0 15 | joy2state EQU _RAMJOYSTATEBASE+2 16 | 17 | -------------------------------------------------------------------------------- /03-VerticalInterrupts/.gitignore: -------------------------------------------------------------------------------- 1 | *.bin 2 | *.lst 3 | -------------------------------------------------------------------------------- /03-VerticalInterrupts/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ************************************ 3 | # Title 4 | # ************************************ 5 | # 6 | # Title: build.sh 7 | # Author: René Richard 8 | # Description: 9 | # 10 | # LICENSE 11 | # 12 | # This file is part of 68kTutorials. 13 | # 68kTutorials is free software: you can redistribute it and/or modify 14 | # it under the terms of the GNU General Public License as published by 15 | # the Free Software Foundation, either version 3 of the License, or 16 | # (at your option) any later version. 17 | # Foobar is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | # GNU General Public License for more details. 21 | # You should have received a copy of the GNU General Public License 22 | # along with 68kTutorials. If not, see . 23 | # 24 | # A POSIX variable 25 | OPTIND=1 # Reset in case getopts has been used previously in the shell. 26 | 27 | # clean the /out directory if it already exists 28 | if test -d out 29 | then 30 | echo "cleaning out directory" 31 | rm -r out/* 32 | else 33 | mkdir out 34 | fi 35 | 36 | # assemble main.asm 37 | asmx -C 68000 -e -w -b 0 -l out/rom.lst -o out/rom.bin -- main.68k 38 | 39 | # check for options 40 | while getopts ":d" opt; do 41 | case "$opt" in 42 | d) 43 | echo "debug selected - starting mess" >&2 44 | mess genesis -cart out/rom.bin -debug 45 | ;; 46 | \?) 47 | echo "Invalid Option: -$OPTARG" >&2 48 | ;; 49 | esac 50 | done 51 | 52 | # Shift off the options and optional --. 53 | shift "$((OPTIND-1))" 54 | -------------------------------------------------------------------------------- /03-VerticalInterrupts/header.68k: -------------------------------------------------------------------------------- 1 | ; ************************************ 2 | ; Title 3 | ; ************************************ 4 | ; 5 | ; Title: header.asm 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; Foobar is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ; ****************************************************************** 29 | ; Sega Megadrive ROM header 30 | ; ****************************************************************** 31 | dc.l $00FFFF00 ; Initial stack pointer value 32 | dc.l EntryPoint ; Start of program 33 | dc.l Exception ; Bus error 34 | dc.l Exception ; Address error 35 | dc.l Exception ; Illegal instruction 36 | dc.l Exception ; Division by zero 37 | dc.l Exception ; CHK exception 38 | dc.l Exception ; TRAPV exception 39 | dc.l Exception ; Privilege violation 40 | dc.l Exception ; TRACE exception 41 | dc.l Exception ; Line-A emulator 42 | dc.l Exception ; Line-F emulator 43 | dc.l Exception ; Unused (reserved) 44 | dc.l Exception ; Unused (reserved) 45 | dc.l Exception ; Unused (reserved) 46 | dc.l Exception ; Unused (reserved) 47 | dc.l Exception ; Unused (reserved) 48 | dc.l Exception ; Unused (reserved) 49 | dc.l Exception ; Unused (reserved) 50 | dc.l Exception ; Unused (reserved) 51 | dc.l Exception ; Unused (reserved) 52 | dc.l Exception ; Unused (reserved) 53 | dc.l Exception ; Unused (reserved) 54 | dc.l Exception ; Unused (reserved) 55 | dc.l Exception ; Spurious exception 56 | dc.l Exception ; IRQ level 1 57 | dc.l ExtInterrupt ; IRQ level 2 (external interrupt) 58 | dc.l Exception ; IRQ level 3 59 | dc.l HBlankInterrupt ; IRQ level 4 (horizontal retrace interrupt) 60 | dc.l Exception ; IRQ level 5 61 | dc.l VBlankInterrupt ; IRQ level 6 (vertical retrace interrupt) 62 | dc.l Exception ; IRQ level 7 63 | dc.l Exception ; TRAP #00 exception 64 | dc.l Exception ; TRAP #01 exception 65 | dc.l Exception ; TRAP #02 exception 66 | dc.l Exception ; TRAP #03 exception 67 | dc.l Exception ; TRAP #04 exception 68 | dc.l Exception ; TRAP #05 exception 69 | dc.l Exception ; TRAP #06 exception 70 | dc.l Exception ; TRAP #07 exception 71 | dc.l Exception ; TRAP #08 exception 72 | dc.l Exception ; TRAP #09 exception 73 | dc.l Exception ; TRAP #10 exception 74 | dc.l Exception ; TRAP #11 exception 75 | dc.l Exception ; TRAP #12 exception 76 | dc.l Exception ; TRAP #13 exception 77 | dc.l Exception ; TRAP #14 exception 78 | dc.l Exception ; TRAP #15 exception 79 | dc.l Exception ; Unused (reserved) 80 | dc.l Exception ; Unused (reserved) 81 | dc.l Exception ; Unused (reserved) 82 | dc.l Exception ; Unused (reserved) 83 | dc.l Exception ; Unused (reserved) 84 | dc.l Exception ; Unused (reserved) 85 | dc.l Exception ; Unused (reserved) 86 | dc.l Exception ; Unused (reserved) 87 | dc.l Exception ; Unused (reserved) 88 | dc.l Exception ; Unused (reserved) 89 | dc.l Exception ; Unused (reserved) 90 | dc.l Exception ; Unused (reserved) 91 | dc.l Exception ; Unused (reserved) 92 | dc.l Exception ; Unused (reserved) 93 | dc.l Exception ; Unused (reserved) 94 | dc.l Exception ; Unused (reserved) 95 | 96 | ; size 012345678901234567890123456789012345678901234567 97 | dc.b "SEGA GENESIS " ; Console name - 16 98 | dc.b "(C)db 2016.MAR" ; Copyright holder and release date - 16 99 | dc.b "DB JOYPAD TUTORIAL " ; Domestic name - 48 100 | dc.b "DB JOYPAD TUTORIAL " ; International name - 48 101 | dc.b "GM INTUTORL-03" ; Version number - 48 102 | dc.w $1234 ; Checksum 103 | dc.b "J " ; I/O support - 16 104 | dc.l $00000000 ; Start address of ROM 105 | dc.l __end ; End address of ROM 106 | dc.l $00FF0000 ; Start address of RAM 107 | dc.l $00FFFFFF ; End address of RAM 108 | dc.l $00000000 ; SRAM enabled 109 | dc.l $00000000 ; Unused 110 | dc.l $00000000 ; Start address of SRAM 111 | dc.l $00000000 ; End address of SRAM 112 | dc.l $00000000 ; Unused 113 | dc.l $00000000 ; Unused 114 | dc.b " " ; Notes (unused) 115 | dc.b "JUE " ; Country codesPARTICULAR 116 | -------------------------------------------------------------------------------- /03-VerticalInterrupts/main.68k: -------------------------------------------------------------------------------- 1 | ; ************************************ 2 | ; Title 3 | ; ************************************ 4 | ; 5 | ; Title: main.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ; ************************************ 29 | ; COMPILER OPTIONS 30 | ; ************************************ 31 | LIST MACRO 32 | LIST NOSYM 33 | LIST NOTEMP 34 | 35 | ; ************************************ 36 | ; SYSTEM DEFINES 37 | ; ************************************ 38 | include 'sys/sysDef.68k' 39 | include 'sys/sysRAM.68k' 40 | 41 | ; ************************************ 42 | ; MACROS 43 | ; ************************************ 44 | include 'sys/sysMacros.68k' 45 | 46 | ; ************************************ 47 | ; HEADER AND STARTUP CODE 48 | ; ************************************ 49 | include 'header.68k' 50 | include 'sys/sysInit.68k' 51 | include 'sys/sysInterrupts.68k' 52 | include 'sys/sysJoypad.68k' 53 | 54 | ; ************************************ 55 | ; USER PROGRAM 56 | ; ************************************ 57 | __main: 58 | include 'tutorial03.68k' 59 | __end: 60 | 61 | ; debug in MESS using 62 | ; mess genesis -cart out/rom.bin -window -debug 63 | -------------------------------------------------------------------------------- /03-VerticalInterrupts/sys/sysDef.68k: -------------------------------------------------------------------------------- 1 | ; ************************************ 2 | ; Title 3 | ; ************************************ 4 | ; 5 | ; Title: sysDef.asm 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; Foobar is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ; ************************************ 29 | ; VDP Addresses 30 | ; ************************************ 31 | VDP_DATA equ $00C00000 32 | VDP_CTRL equ $00C00004 33 | VDP_HVCOUNTER equ $00C00008 34 | VDP_PSG equ $00C00011 35 | 36 | ; VDP Control Masks 37 | VDP_VSRAM_WRITE equ $40000010 38 | VDP_VSRAM_READ equ $00000010 39 | VDP_CRAM_WRITE equ $C0000000 40 | VDP_CRAM_READ equ $00000020 41 | VDP_VRAM_WRITE equ $40000000 42 | VDP_VRAM_READ equ $00000000 43 | 44 | ; ************************************ 45 | ; I/O Addresses 46 | ; ************************************ 47 | IO_VERSIONNO equ $00A10001 48 | IO_DATA_1 equ $00A10003 49 | IO_DATA_2 equ $00A10005 50 | IO_DATA_EXP equ $00A10007 51 | IO_CTRL_1 equ $00A10009 52 | IO_CTRL_2 equ $00A1000B 53 | IO_CTRL_EXP equ $00A1000D 54 | IO_TXDATA_1 equ $00A1000F 55 | IO_RXDATA_1 equ $00A10011 56 | IO_SCTRL_1 equ $00A10013 57 | IO_TXDATA_2 equ $00A10015 58 | IO_RXDATA_2 equ $00A10017 59 | IO_SCTRL_2 equ $00A10019 60 | IO_TXDATA_3 equ $00A1001B 61 | IO_RXDATA_3 equ $00A1001D 62 | IO_SCTRL_EXP equ $00A1001F 63 | 64 | ; ************************************ 65 | ; Z80 Addresses 66 | ; ************************************ 67 | Z80_MEMSPACE equ $00A00000 68 | Z80_RAM equ $00A00000 69 | 70 | ; ************************************ 71 | ; CTRL Addresses 72 | ; ************************************ 73 | CTRL_MEMMODE equ $00A11000 74 | CTRL_Z80BUSREQ equ $00A11100 75 | CTRL_Z80RESET equ $00A11200 76 | CTRL_TIME equ $00A13000 77 | CTRL_TMSS equ $00A14000 78 | 79 | ; ************************************ 80 | ; Other Addresses 81 | ; ************************************ 82 | M68K_RAM equ $00FF0000 83 | 84 | ; ************************************ 85 | ; JOY bit numbers SACBRLDU 86 | ; ************************************ 87 | JOY_UP equ 0 88 | JOY_DOWN equ 1 89 | JOY_LEFT equ 2 90 | JOY_RIGHT equ 3 91 | JOY_A equ 6 92 | JOY_B equ 4 93 | JOY_C equ 5 94 | JOY_START equ 7 95 | -------------------------------------------------------------------------------- /03-VerticalInterrupts/sys/sysInit.68k: -------------------------------------------------------------------------------- 1 | ; ************************************ 2 | ; Title 3 | ; ************************************ 4 | ; 5 | ; Title: sysInit.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ; ************************************ 29 | ; Start of System Initialization 30 | ; ************************************ 31 | 32 | ORG $00000200 ; header section should get us to $200 33 | ; but ORG in case we made a mistake (ASMX will complain) 34 | EntryPoint: ; Entry point address set in ROM header 35 | 36 | ; ************************************ 37 | ; Test reset button 38 | ; ************************************ 39 | tst.w $00A10008 ; Test mystery reset (expansion port reset?) 40 | bne.w Main ; Branch if Not Equal (to zero) - to Main 41 | tst.w $00A1000C ; Test reset button 42 | bne.w Main ; Branch if Not Equal (to zero) - to Main 43 | 44 | ; ************************************ 45 | ; Clear RAM 46 | ; ************************************ 47 | clr.l D0 ; Place a 0 into d0, ready to copy to each longword of RAM 48 | lea M68K_RAM, A0 ; A0 points to beginning of RAM 49 | move.l #$00004000, D1 ; Clearing 64k's worth of longwords 50 | .Clear: 51 | move.l D0, (A0)+ ; Post-inc faster than Pre-dec (as last tutorial) 52 | dbra D1, .Clear ; Decrement d0, repeat until depleted 53 | 54 | ; ************************************ 55 | ; Write TMSS, get System Region 56 | ; ************************************ 57 | move.w #(20<<4), D1 ; millis timer init (20ms for PAL) 58 | ; the millis timer is in D7 and has a binary point at bit4, 59 | move.b IO_VERSIONNO, D0 ; Move Megadrive hardware version to d0 60 | btst #6, D0 ; Test VMOD bit for region (PAL = 1, NTSC = 0) 61 | bne.s .skipForPal 62 | subi.w #53, D1 ; change millis timer to ~16.7 for NTSC (3.3 * 16 = 52.8) 63 | .skipForPal 64 | move.w D1, sysmillisinc ; store value to sysregion 65 | andi.b #$0F, D0 ; The version is stored in last four bits, so mask it with 0F 66 | beq.s .SkipTMSS ; If version is equal to 0, skip TMSS signature 67 | move.l #'SEGA', CTRL_TMSS ; Move the string "SEGA" to $A14000 68 | .SkipTMSS: 69 | 70 | ; ************************************ 71 | ; Init Z80 72 | ; ************************************ 73 | Z80Reset_m 74 | Z80Request_m 75 | 76 | ; clear the Z80's 8KB of RAM 77 | move.w #$2000, D0 ; 8KB of Z80 RAM to clear 78 | lea Z80_RAM, A1 ; A1 points to Z80 RAM 79 | .ClearZ80 80 | clr.b (A1)+ ; clear bytes, $00 is Z80 nop 81 | dbra D0, .ClearZ80 82 | 83 | ; load simple program to Z80 84 | lea Z80Data, A0 ; Load address of data into a0 85 | lea Z80_RAM, A1 ; Copy Z80 RAM address to a1 86 | move.l #Z80DataEnd-Z80Data, D0 ; Auto-calculate size of transfer using labels 87 | .CopyZ80: 88 | move.b (A0)+, (A1)+ ; Copy data, and increment the source/dest addresses 89 | dbra D0, .CopyZ80 90 | 91 | Z80Reset_m 92 | Z80Release_m 93 | 94 | ; ************************************ 95 | ; Init PSG 96 | ; ************************************ 97 | move.b $9F, VDP_PSG ; mutes all PSG channels 98 | move.b $BF, VDP_PSG 99 | move.b $DF, VDP_PSG 100 | move.b $FF, VDP_PSG 101 | 102 | ; ************************************ 103 | ; Init VDP 104 | ; DO - iterations 105 | ; D1.uw - register number in VDP 106 | ; D1.lw - register value 107 | ; A0 - pointer to VDP register value array 108 | ; ************************************ 109 | lea VDPRegisters, A0 ; Load address of register table into a0 110 | move.l #24, D0 ; 24 registers to write 111 | move.l #$00008000, d1 ; 'Set register 0' command (and clear the rest of d1 ready) 112 | 113 | .CopyVDP: 114 | move.b (A0)+, D1 ; Move register value to lower byte of d1 115 | move.w D1, VDP_CTRL ; Write command and value to VDP control port 116 | add.w #$0100, D1 ; Increment register # 117 | dbra D0, .CopyVDP 118 | 119 | ; ************************************ 120 | ; Init IO Ports 121 | ; ************************************ 122 | move.b #$40, IO_CTRL_1 ; Controller port 1 CTRL, TH = output 123 | move.b #$40, IO_CTRL_2 ; Controller port 2 CTRL, TH = output 124 | move.b #$00, IO_CTRL_EXP ; EXP port CTRL 125 | move.b #$40, IO_DATA_1 ; Idle with TH = '1' 126 | move.b #$40, IO_DATA_2 ; Idle with TH = '1' 127 | 128 | ; ************************************ 129 | ; Cleanup 130 | ; ************************************ 131 | lea M68K_RAM, A0 ; A0 points to $00 value in RAM (has been cleared) 132 | movem.l (A0), D0-D7/A1-A6 ; Multiple move zero to all registers 133 | suba.l A0, A0 ; Clear A0 134 | 135 | ; Init status register (no trace, supervisor mode, all interrupt levels enabled, clear condition code bits) 136 | move #$2000, SR 137 | 138 | ; ************************************ 139 | ; Main 140 | ; ************************************ 141 | Main: 142 | jmp __main ; Begin external main 143 | 144 | ; ************************************ 145 | ; Data 146 | ; ************************************ 147 | 148 | Z80Data: 149 | dc.w $af01, $d91f 150 | dc.w $1127, $0021 151 | dc.w $2600, $f977 152 | dc.w $edb0, $dde1 153 | dc.w $fde1, $ed47 154 | dc.w $ed4f, $d1e1 155 | dc.w $f108, $d9c1 156 | dc.w $d1e1, $f1f9 157 | dc.w $f3ed, $5636 158 | dc.w $e9e9, $8104 159 | dc.w $8f01 160 | Z80DataEnd: 161 | 162 | VDPRegisters: 163 | dc.b $04 ; 0: Horiz. interrupt off 164 | dc.b $74 ; 1: Vert. interrupt on, screen blank off, DMA on, V28 mode (40 cells vertically), Genesis mode on 165 | dc.b $30 ; 2: Pattern table for Scroll Plane A at $C000 (bits 3-5) 166 | dc.b $40 ; 3: Pattern table for Window Plane at $10000 (bits 1-5) 167 | dc.b $05 ; 4: Pattern table for Scroll Plane B at $A000 (bits 0-2) 168 | dc.b $70 ; 5: Sprite table at $E000 (bits 0-6) 169 | dc.b $00 ; 6: Unused 170 | dc.b $00 ; 7: Background colour - bits 0-3 = colour, bits 4-5 = palette 171 | dc.b $00 ; 8: Unused 172 | dc.b $00 ; 9: Unused 173 | dc.b $00 ; 10: Frequency of Horiz. interrupt in Rasters (number of lines travelled by the beam) 174 | dc.b $00 ; 11: External interrupts off, V/H scrolling on 175 | dc.b $81 ; 12: Shadows and highlights off, interlace off, H40 mode (64 cells horizontally) 176 | dc.b $34 ; 13: Horiz. scroll table at $D000 (bits 0-5) 177 | dc.b $00 ; 14: Unused 178 | dc.b $00 ; 15: Autoincrement off 179 | dc.b $01 ; 16: Vert. scroll 32, Horiz. scroll 64 180 | dc.b $00 ; 17: Window Plane X pos 0 left (pos in bits 0-4, left/right in bit 7) 181 | dc.b $00 ; 18: Window Plane Y pos 0 up (pos in bits 0-4, up/down in bit 7) 182 | dc.b $00 ; 19: DMA length lo byte 183 | dc.b $00 ; 20: DMA length hi byte 184 | dc.b $00 ; 21: DMA source address lo byte 185 | dc.b $00 ; 22: DMA source address mid byte 186 | dc.b $00 ; 23: DMA source address hi byte, memory-to-VRAM mode (bits 6-7) 187 | VDPRegistersEnd: 188 | -------------------------------------------------------------------------------- /03-VerticalInterrupts/sys/sysInterrupts.68k: -------------------------------------------------------------------------------- 1 | ; ************************************ 2 | ; Title 3 | ; ************************************ 4 | ; 5 | ; Title: sysInterrupts.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ; ************************************ 29 | ; Horizontal Interrupts 30 | ; ************************************ 31 | HBlankInterrupt: 32 | bset #0, intflags ; set hintflag 33 | rte 34 | 35 | ; ************************************ 36 | ; Vertical Interrupts 37 | ; ************************************ 38 | VBlankInterrupt: 39 | addq.w #1, sysframecnt ; increment vint counter 40 | add.l sysmillisinc, D7 ; D7 = global millis counter 41 | bset #1, intflags ; set vintflag 42 | tst.l vintvector ; test vintvector 43 | beq.s .noVector ; if vintvector = 0, get out of here! 44 | .vectorValid 45 | movem.l D0-D6/A0-A6, -(SP) ; push context to stack 46 | movea.l vintvector, A0 ; put vintvector in A0 47 | jsr (A0) ; jsr to vintvector 48 | movem.l (SP)+, D0-D6/A0-A6 ; pop context from stack 49 | .noVector 50 | rte ; return to main code 51 | 52 | ; ************************************ 53 | ; External Interrupts 54 | ; ************************************ 55 | ExtInterrupt: 56 | bset #2, intflags ; set xintflag 57 | rte 58 | 59 | ; ************************************ 60 | ; Macros 61 | ; ************************************ 62 | sysInt_VDPDisableHInt MACRO 63 | move.w #$8004, VDP_CTRL 64 | ENDM 65 | 66 | sysInt_VDPEnableHInt MACRO 67 | move.w #$8014, VDP_CTRL 68 | ENDM 69 | 70 | ; ************************************ 71 | ; Exception 72 | ; ************************************ 73 | Exception: 74 | stop #$2700 ; Halt CPU 75 | 76 | -------------------------------------------------------------------------------- /03-VerticalInterrupts/sys/sysJoypad.68k: -------------------------------------------------------------------------------- 1 | ; ************************************ 2 | ; Title 3 | ; ************************************ 4 | ; 5 | ; Title: sysJoypad.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ; ************************************ 29 | ; JOYPAD_ReadPad01: 30 | ; 31 | ; destroys: 32 | ; A0, A1, D5, D6 33 | ; returns: 34 | ; D6 = SACBRLDU 35 | ; joy1State (RAM) = D6 36 | ; ************************************ 37 | JOYPAD_ReadPad01: 38 | lea IO_DATA_1, A0 ; load data_1 address 39 | lea v_joy1State, A1 ; point to RAM placeholder for joystate 40 | move.b (A0), D6 ; read status j1 = 00CBRLDU 41 | move.b #$00, (A0) ; set TH low 42 | nop ; wait to settle 43 | nop ; 44 | move.b (A0), D5 ; read status = 00SA00DU 45 | rol.b #2, D5 ; SA00DU?? 46 | andi.b #$C0, D5 ; SA000000 47 | or.b D5, D6 ; D6 = SACBRLDU 48 | not.b D6 ; invert, 1 = pressed 49 | move.b #$40, (A0) ; set TH high for next pass 50 | move.w D6, (A1) ; store to RAM 51 | rts 52 | 53 | ; ************************************ 54 | ; sysJoy_Read3ButtonBoth 55 | ; 56 | ; destroys: 57 | ; A0, A1, D0, D1 58 | ; ************************************ 59 | sysJoy_Read3Button: 60 | lea IO_DATA_1, A0 ; load data_1 address 61 | lea v_joy1State, A1 ; point to RAM placeholder for joystate 62 | bsr.s .read ; 63 | addq.w #2, A0 ; 64 | 65 | .read 66 | move.b (A0), D0 ; read status of j1 = 00CBRLDU, TH already high 67 | move.b #$00, (A0) ; set TH low 68 | nop ; wait to settle 69 | nop ; 70 | move.b (A0), D1 ; read status = 00SA00DU 71 | move.b #$40, (A0) ; set TH high for next pass 72 | rol.b #2, D1 ; SA00DU?? 73 | andi.b #$C0, D1 ; SA000000 74 | or.b D1, D0 ; D0.b = SACBRLDU j1 75 | not.b D0 ; 1 = pressed 76 | move.w (A1), D1 ; get previous joypad state 77 | eor.w D0, D1 ; diff current with previous 78 | move.w D0, (A1)+ ; store current joypad state 79 | and.w D0, D1 80 | move.w D1, (A1)+ ; store held joypad state 81 | rts 82 | -------------------------------------------------------------------------------- /03-VerticalInterrupts/sys/sysMacros.68k: -------------------------------------------------------------------------------- 1 | ; ************************************ 2 | ; Title 3 | ; ************************************ 4 | ; 5 | ; Title: sysMacros.asm 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; Foobar is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ; ************************************ 29 | ; MACROS 30 | ; ************************************ 31 | Z80Reset_m MACRO 32 | move.w #$0000, CTRL_Z80RESET 33 | exg.l A0,A1 ; waste some time 34 | exg.l A1,A0 35 | move.w #$0100, CTRL_Z80RESET 36 | ENDM 37 | 38 | Z80Request_m MACRO 39 | move.w #$0100, CTRL_Z80BUSREQ 40 | .Wait\? 41 | btst.b #0, CTRL_Z80BUSREQ 42 | bne.s .Wait\? 43 | ENDM 44 | 45 | Z80Release_m MACRO 46 | move.w #$0000, CTRL_Z80BUSREQ 47 | ENDM 48 | 49 | WaitVBlankStart_m MACRO 50 | .Wait\? 51 | move.w VDP_CTRL, D0 ; Move VDP status word to d0 52 | andi.w #$0008, D0 ; AND with bit 4 (vblank), result in status register 53 | bne.s .Wait\? ; Branch if not equal (to zero) 54 | ENDM 55 | 56 | WaitVBlankEnd_m MACRO 57 | .Wait\? 58 | move.w VDP_CTRL, D0 ; Move VDP status word to d0 59 | andi.w #$0008, D0 ; AND with bit 4 (vblank), result in status register 60 | beq.s .Wait\? ; Branch if equal (to zero) 61 | ENDM 62 | -------------------------------------------------------------------------------- /03-VerticalInterrupts/sys/sysRAM.68k: -------------------------------------------------------------------------------- 1 | ; ************************************ 2 | ; Title 3 | ; ************************************ 4 | ; 5 | ; Title: sysRAM.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; Foobar is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ; ************************************ 29 | ; Soft Interrupt Vectors 30 | ; ************************************ 31 | _RAMVECTORSBASE EQU $FFFF00 32 | vintvector EQU _RAMVECTORSBASE+0 33 | hintvector EQU _RAMVECTORSBASE+4 34 | xintvector EQU _RAMVECTORSBASE+8 35 | intflags EQU _RAMVECTORSBASE+12 36 | _SIZEOFRAMVECTORS EQU 16 37 | 38 | ; ************************************ 39 | ; Joypads 40 | ; ************************************ 41 | _RAMJOYSTATEBASE EQU _RAMVECTORSBASE + _SIZEOFRAMVECTORS 42 | v_joy1State EQU _RAMJOYSTATEBASE+0 43 | v_joy1Held EQU _RAMJOYSTATEBASE+2 44 | v_joy2State EQU _RAMJOYSTATEBASE+4 45 | v_joy2Held EQU _RAMJOYSTATEBASE+6 46 | _SIZEOFRAMJOY EQU 8 47 | 48 | ; ************************************ 49 | ; System Timing 50 | ; ************************************ 51 | _SYSTIMINGBASE EQU _RAMJOYSTATEBASE + _SIZEOFRAMJOY 52 | sysmillisinc EQU _SYSTIMINGBASE+0 53 | sysframecnt EQU _SYSTIMINGBASE+2 54 | 55 | -------------------------------------------------------------------------------- /03-VerticalInterrupts/tutorial03.68k: -------------------------------------------------------------------------------- 1 | ; ************************************ 2 | ; Title 3 | ; ************************************ 4 | ; 5 | ; Title: tutorial03.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ; ************************************ 29 | ; Tutorial 03 30 | ; ************************************ 31 | Tutorial03Entry: 32 | 33 | move.w #2, D2 ; test context saving in Vint 34 | move.w #3, D3 35 | move.w #4, D4 36 | move.w #5, D5 37 | move.w #6, D6 38 | movea.l #$10, A0 39 | movea.l #$11, A1 40 | movea.l #$12, A2 41 | movea.l #$13, A3 42 | movea.l #$14, A4 43 | movea.l #$15, A5 44 | movea.l #$16, A6 45 | 46 | ; TODO 47 | ; only enable VDP interrupts here 48 | 49 | .newFrame 50 | lea intflags, A0 ; A0 points to intflags 51 | .syncVint 52 | btst #1, (A0) ; test if a Vertical Interrupt occured 53 | beq.s .syncVint ; wait until vint occurs, bit0 set = vint has happened 54 | bclr #1, (A0) ; clear the intflag 55 | 56 | jsr sysJoy_Read3Button ; read joypad1 state 57 | 58 | move.w sysframecnt, D0 ; load the sysframecnt into D0 59 | andi.w #$0003, D0 ; look at the lowest two bits of vintcounter 60 | bne.s .newFrame ; if zero, load vintvector address, this should execute every 4 frames 61 | move.l #VintRoutine, vintvector 62 | bra.s .newFrame 63 | 64 | VintRoutine: 65 | move.l D0, vintvector ; clear the vintvector address 66 | addq.w #1, M68K_RAM ; increment a variable, should be 1/4 the frame rate 67 | rts ; return 68 | -------------------------------------------------------------------------------- /04-PatternsIntro/.gitignore: -------------------------------------------------------------------------------- 1 | *.bin 2 | *.lst 3 | -------------------------------------------------------------------------------- /04-PatternsIntro/04-Patterns.geany: -------------------------------------------------------------------------------- 1 | [file_prefs] 2 | final_new_line=true 3 | ensure_convert_new_lines=false 4 | strip_trailing_spaces=false 5 | replace_tabs=false 6 | 7 | [indentation] 8 | indent_width=4 9 | indent_type=1 10 | indent_hard_tab_width=8 11 | detect_indent=false 12 | detect_indent_width=false 13 | indent_mode=2 14 | 15 | [project] 16 | name=04-Patterns 17 | base_path=/home/rene/Git/68kTutorials/04-PatternsIntro 18 | description= 19 | 20 | [long line marker] 21 | long_line_behaviour=1 22 | long_line_column=72 23 | 24 | [files] 25 | current_page=2 26 | FILE_NAME_0=4322;68k;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F04-PatternsIntro%2Fheader.68k;0;4 27 | FILE_NAME_1=1847;68k;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F04-PatternsIntro%2Fmain.68k;0;4 28 | FILE_NAME_2=3172;68k;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F04-PatternsIntro%2Ftutorial04.68k;0;4 29 | FILE_NAME_3=2027;68k;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F04-PatternsIntro%2Fsys%2FsysDef.68k;0;4 30 | FILE_NAME_4=9126;68k;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F04-PatternsIntro%2Fsys%2FsysInit.68k;0;4 31 | FILE_NAME_5=0;68k;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F04-PatternsIntro%2Fsys%2FsysInterrupts.68k;0;4 32 | FILE_NAME_6=2911;68k;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F04-PatternsIntro%2Fsys%2FsysJoypad.68k;0;4 33 | -------------------------------------------------------------------------------- /04-PatternsIntro/README.MD: -------------------------------------------------------------------------------- 1 | #Tutorial 04 - Introduction to Patterns 2 | -------------------------------------------------------------------------------- /04-PatternsIntro/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ************************************ 3 | # Title 4 | # ************************************ 5 | # 6 | # Title: build.sh 7 | # Author: René Richard 8 | # Description: 9 | # 10 | # LICENSE 11 | # 12 | # This file is part of 68kTutorials. 13 | # 68kTutorials is free software: you can redistribute it and/or modify 14 | # it under the terms of the GNU General Public License as published by 15 | # the Free Software Foundation, either version 3 of the License, or 16 | # (at your option) any later version. 17 | # Foobar is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | # GNU General Public License for more details. 21 | # You should have received a copy of the GNU General Public License 22 | # along with 68kTutorials. If not, see . 23 | # 24 | # A POSIX variable 25 | OPTIND=1 # Reset in case getopts has been used previously in the shell. 26 | 27 | # clean the /out directory if it already exists 28 | if test -d out 29 | then 30 | echo "cleaning out directory" 31 | rm -r out/* 32 | else 33 | mkdir out 34 | fi 35 | 36 | # assemble main.asm 37 | asmx -C 68000 -e -w -b 0 -l out/rom.lst -o out/rom.bin -- main.68k 38 | 39 | # check for options 40 | while getopts ":d" opt; do 41 | case "$opt" in 42 | d) 43 | echo "debug selected - starting mess" >&2 44 | mess genesis -cart out/rom.bin -debug 45 | ;; 46 | \?) 47 | echo "Invalid Option: -$OPTARG" >&2 48 | ;; 49 | esac 50 | done 51 | 52 | # Shift off the options and optional --. 53 | shift "$((OPTIND-1))" 54 | -------------------------------------------------------------------------------- /04-PatternsIntro/header.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; ROM HEADER 3 | ;{****************************************************************** 4 | ; 5 | ; Title: header.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; 68000 Vector Table 32 | ;{****************************************************************** 33 | dc.l 0x00FFFF00 ; Initial stack pointer value 34 | dc.l EntryPoint ; Start of program 35 | dc.l Exception ; Bus error 36 | dc.l Exception ; Address error 37 | dc.l Exception ; Illegal instruction 38 | dc.l Exception ; Division by zero 39 | dc.l Exception ; CHK exception 40 | dc.l Exception ; TRAPV exception 41 | dc.l Exception ; Privilege violation 42 | dc.l Exception ; TRACE exception 43 | dc.l Exception ; Line-A emulator 44 | dc.l Exception ; Line-F emulator 45 | dc.l Exception ; Unused (reserved) 46 | dc.l Exception ; Unused (reserved) 47 | dc.l Exception ; Unused (reserved) 48 | dc.l Exception ; Unused (reserved) 49 | dc.l Exception ; Unused (reserved) 50 | dc.l Exception ; Unused (reserved) 51 | dc.l Exception ; Unused (reserved) 52 | dc.l Exception ; Unused (reserved) 53 | dc.l Exception ; Unused (reserved) 54 | dc.l Exception ; Unused (reserved) 55 | dc.l Exception ; Unused (reserved) 56 | dc.l Exception ; Unused (reserved) 57 | dc.l Exception ; Spurious exception 58 | dc.l Exception ; IRQ level 1 59 | dc.l ExtInterrupt ; IRQ level 2 (external interrupt) 60 | dc.l Exception ; IRQ level 3 61 | dc.l HBlankInterrupt ; IRQ level 4 (horizontal retrace interrupt) 62 | dc.l Exception ; IRQ level 5 63 | dc.l VBlankInterrupt ; IRQ level 6 (vertical retrace interrupt) 64 | dc.l Exception ; IRQ level 7 65 | dc.l Exception ; TRAP #00 exception 66 | dc.l Exception ; TRAP #01 exception 67 | dc.l Exception ; TRAP #02 exception 68 | dc.l Exception ; TRAP #03 exception 69 | dc.l Exception ; TRAP #04 exception 70 | dc.l Exception ; TRAP #05 exception 71 | dc.l Exception ; TRAP #06 exception 72 | dc.l Exception ; TRAP #07 exception 73 | dc.l Exception ; TRAP #08 exception 74 | dc.l Exception ; TRAP #09 exception 75 | dc.l Exception ; TRAP #10 exception 76 | dc.l Exception ; TRAP #11 exception 77 | dc.l Exception ; TRAP #12 exception 78 | dc.l Exception ; TRAP #13 exception 79 | dc.l Exception ; TRAP #14 exception 80 | dc.l Exception ; TRAP #15 exception 81 | dc.l Exception ; Unused (reserved) 82 | dc.l Exception ; Unused (reserved) 83 | dc.l Exception ; Unused (reserved) 84 | dc.l Exception ; Unused (reserved) 85 | dc.l Exception ; Unused (reserved) 86 | dc.l Exception ; Unused (reserved) 87 | dc.l Exception ; Unused (reserved) 88 | dc.l Exception ; Unused (reserved) 89 | dc.l Exception ; Unused (reserved) 90 | dc.l Exception ; Unused (reserved) 91 | dc.l Exception ; Unused (reserved) 92 | dc.l Exception ; Unused (reserved) 93 | dc.l Exception ; Unused (reserved) 94 | dc.l Exception ; Unused (reserved) 95 | dc.l Exception ; Unused (reserved) 96 | dc.l Exception ; Unused (reserved) 97 | ;}****************************************************************** 98 | 99 | ; ****************************************************************** 100 | ; Genesis ROM Info 101 | ;{****************************************************************** 102 | ; size 012345678901234567890123456789012345678901234567 103 | dc.b "SEGA GENESIS " ; Console name - 16 104 | dc.b "(C)db 2016.MAR" ; Copyright holder and release date - 16 105 | dc.b "DB PATTERNS INTRO TUTORIAL " ; Domestic name - 48 106 | dc.b "DB PATTERNS INTRO TUTORIAL " ; International name - 48 107 | dc.b "GM INTUTORL-04" ; Version number - 48 108 | dc.w 0x1234 ; Checksum 109 | dc.b "J " ; I/O support - 16 110 | dc.l 0x00000000 ; Start address of ROM 111 | dc.l __end ; End address of ROM 112 | dc.l 0x00FF0000 ; Start address of RAM 113 | dc.l 0x00FFFFFF ; End address of RAM 114 | dc.l 0x00000000 ; SRAM enabled 115 | dc.l 0x00000000 ; Unused 116 | dc.l 0x00000000 ; Start address of SRAM 117 | dc.l 0x00000000 ; End address of SRAM 118 | dc.l 0x00000000 ; Unused 119 | dc.l 0x00000000 ; Unused 120 | dc.b " " ; Notes (unused) 121 | dc.b "JUE " ; Country codesPARTICULAR 122 | ;}****************************************************************** 123 | -------------------------------------------------------------------------------- /04-PatternsIntro/main.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; MAIN 3 | ;{****************************************************************** 4 | ; 5 | ; Title: main.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; ASSEMBLER OPTIONS 32 | ;{****************************************************************** 33 | LIST MACRO 34 | LIST NOSYM 35 | LIST NOTEMP 36 | ;}****************************************************************** 37 | 38 | ; ****************************************************************** 39 | ; System Defines 40 | ;{****************************************************************** 41 | include 'sys/sysDef.68k' 42 | include 'sys/sysRAM.68k' 43 | ;}****************************************************************** 44 | 45 | ; ****************************************************************** 46 | ; Macros 47 | ;{****************************************************************** 48 | include 'sys/sysMacros.68k' 49 | ;}****************************************************************** 50 | 51 | ; ****************************************************************** 52 | ; Header and Startup Code 53 | ;{****************************************************************** 54 | include 'header.68k' 55 | include 'sys/sysInit.68k' 56 | include 'sys/sysInterrupts.68k' 57 | include 'sys/sysJoypad.68k' 58 | ;}****************************************************************** 59 | 60 | ; ****************************************************************** 61 | ; User Program 62 | ;{****************************************************************** 63 | __main: 64 | include 'tutorial04.68k' 65 | __end: 66 | ;}****************************************************************** 67 | 68 | -------------------------------------------------------------------------------- /04-PatternsIntro/sys/sysDef.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; SYSTEM DEFINITIONS 3 | ;{****************************************************************** 4 | ; 5 | ; Title: sysDef.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; VDP Addresses 32 | ;{****************************************************************** 33 | VDP_DATA equ 0x00C00000 34 | VDP_CTRL equ 0x00C00004 35 | VDP_HVCOUNTER equ 0x00C00008 36 | VDP_PSG equ 0x00C00011 37 | ;}****************************************************************** 38 | 39 | ; ****************************************************************** 40 | ; VDP Control Masks 41 | ;{****************************************************************** 42 | VDP_VSRAM_WRITE equ 0x40000010 43 | VDP_VSRAM_READ equ 0x00000010 44 | VDP_CRAM_WRITE equ 0xC0000000 45 | VDP_CRAM_READ equ 0x00000020 46 | VDP_VRAM_WRITE equ 0x40000000 47 | VDP_VRAM_READ equ 0x00000000 48 | 49 | NT_PRI1 equ 0x8000 50 | NT_PRI0 equ 0x0000 51 | NT_PAL0 equ 0x0000 52 | NT_PAL1 equ 0x2000 53 | NT_PAL2 equ 0x4000 54 | NT_PAL3 equ 0x6000 55 | NT_VF equ 0x1000 56 | NT_HF equ 0x0800 57 | 58 | ;}****************************************************************** 59 | 60 | ; ****************************************************************** 61 | ; I/O Addresses 62 | ;{****************************************************************** 63 | IO_VERSIONNO equ 0x00A10001 64 | IO_DATA_1 equ 0x00A10003 65 | IO_DATA_2 equ 0x00A10005 66 | IO_DATA_EXP equ 0x00A10007 67 | IO_CTRL_1 equ 0x00A10009 68 | IO_CTRL_2 equ 0x00A1000B 69 | IO_CTRL_EXP equ 0x00A1000D 70 | IO_TXDATA_1 equ 0x00A1000F 71 | IO_RXDATA_1 equ 0x00A10011 72 | IO_SCTRL_1 equ 0x00A10013 73 | IO_TXDATA_2 equ 0x00A10015 74 | IO_RXDATA_2 equ 0x00A10017 75 | IO_SCTRL_2 equ 0x00A10019 76 | IO_TXDATA_3 equ 0x00A1001B 77 | IO_RXDATA_3 equ 0x00A1001D 78 | IO_SCTRL_EXP equ 0x00A1001F 79 | ;}****************************************************************** 80 | 81 | ; ****************************************************************** 82 | ; Z80 Addresses 83 | ;{****************************************************************** 84 | Z80_MEMSPACE equ 0x00A00000 85 | Z80_RAM equ 0x00A00000 86 | ;}****************************************************************** 87 | 88 | ; ****************************************************************** 89 | ; CTRL Addresses 90 | ;{****************************************************************** 91 | CTRL_MEMMODE equ 0x00A11000 92 | CTRL_Z80BUSREQ equ 0x00A11100 93 | CTRL_Z80RESET equ 0x00A11200 94 | CTRL_TIME equ 0x00A13000 95 | CTRL_TMSS equ 0x00A14000 96 | ;}****************************************************************** 97 | 98 | ; ****************************************************************** 99 | ; Other Addresses 100 | ;{****************************************************************** 101 | M68K_RAM equ 0x00FF0000 102 | ;}****************************************************************** 103 | 104 | ; ****************************************************************** 105 | ; JOY bit numbers SACBRLDU 106 | ;{****************************************************************** 107 | JOY_UP equ 0 108 | JOY_DOWN equ 1 109 | JOY_LEFT equ 2 110 | JOY_RIGHT equ 3 111 | JOY_A equ 6 112 | JOY_B equ 4 113 | JOY_C equ 5 114 | JOY_START equ 7 115 | ;}****************************************************************** 116 | -------------------------------------------------------------------------------- /04-PatternsIntro/sys/sysInterrupts.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; SYSTEM INTERRUPTS 3 | ;{****************************************************************** 4 | ; 5 | ; Title: sysInterrupts.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; Vertical Interrupts - Level 6 32 | ;{****************************************************************** 33 | 34 | VBlankInterrupt: 35 | addq.w #1, sysframecnt ; increment vint counter 36 | add.l sysmillisinc, d7 ; D7 = global millis counter 37 | bset #1, intflags ; set vintflag 38 | tst.l vintvector ; test vintvector 39 | beq.s .noVector ; if vintvector = 0, get out of here! 40 | .vectorValid 41 | movem.l d0-d6/a0-a6, -(sp) ; push context to stack 42 | movea.l vintvector, a0 ; put vintvector in A0 43 | jsr (a0) ; jsr to vintvector 44 | movem.l (sp)+, d0-d6/a0-a6 ; pop context from stack 45 | .noVector 46 | rte ; return to main code 47 | ;}****************************************************************** 48 | 49 | ; ****************************************************************** 50 | ; Horizontal Interrupts - Level 4 51 | ;{****************************************************************** 52 | HBlankInterrupt: 53 | bset #0, intflags ; set hintflag 54 | rte 55 | ;}****************************************************************** 56 | 57 | ; ****************************************************************** 58 | ; External Interrupts - Level 2 59 | ;{****************************************************************** 60 | ExtInterrupt: 61 | bset #2, intflags ; set xintflag 62 | rte 63 | ;}****************************************************************** 64 | 65 | ; ****************************************************************** 66 | ; Macros 67 | ;{****************************************************************** 68 | sysInt_VDPDisableHInt MACRO 69 | move.w #0x8004, VDP_CTRL 70 | ENDM 71 | 72 | sysInt_VDPEnableHInt MACRO 73 | move.w #0x8014, VDP_CTRL 74 | ENDM 75 | ;}****************************************************************** 76 | 77 | ; ****************************************************************** 78 | ; Exception 79 | ;{****************************************************************** 80 | Exception: 81 | stop #0x2700 ; Halt CPU 82 | ;}****************************************************************** 83 | -------------------------------------------------------------------------------- /04-PatternsIntro/sys/sysJoypad.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; SYSTEM JOYPAD 3 | ;{****************************************************************** 4 | ; 5 | ; Title: sysJoypad.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; JOYPAD_ReadPad01: 32 | ; 33 | ; destroys: 34 | ; A0, A1, D5, D6 35 | ; returns: 36 | ; D6 = SACBRLDU 37 | ; joy1State (RAM) = D6 38 | ;{****************************************************************** 39 | JOYPAD_ReadPad01: 40 | lea IO_DATA_1, a0 ; load data_1 address 41 | lea v_joy1State, a1 ; point to RAM placeholder for joystate 42 | move.b (a0), d6 ; read status j1 = 00CBRLDU 43 | move.b #0x00, (a0) ; set TH low 44 | nop ; wait to settle 45 | nop ; 46 | move.b (a0), d5 ; read status = 00SA00DU 47 | rol.b #2, d5 ; SA00DU?? 48 | andi.b #0x00, d5 ; SA000000 49 | or.b d5, d6 ; D6 = SACBRLDU 50 | not.b d6 ; invert, 1 = pressed 51 | move.b #0x00, (a0) ; set TH high for next pass 52 | move.w d6, (a1) ; store to RAM 53 | rts 54 | ;}****************************************************************** 55 | 56 | ; ****************************************************************** 57 | ; sysJoy_Read3Button 58 | ; 59 | ; destroys: 60 | ; A0, A1, D0, D1 61 | ;{****************************************************************** 62 | sysJoy_Read3Button: 63 | lea IO_DATA_1, a0 ; load data_1 address 64 | lea v_joy1State, a1 ; point to RAM placeholder for joystate 65 | bsr.s .read ; 66 | addq.w #2, a0 ; 67 | 68 | .read 69 | move.b (a0), d0 ; read status of j1 = 00CBRLDU, TH already high 70 | move.b #0x00, (a0) ; set TH low 71 | nop ; wait to settle 72 | nop ; 73 | move.b (a0), d1 ; read status = 00SA00DU 74 | move.b #0x40, (a0) ; set TH high for next pass 75 | rol.b #2, d1 ; SA00DU?? 76 | andi.b #0xC0, d1 ; SA000000 77 | or.b d1, d0 ; D0.b = SACBRLDU j1 78 | not.b d0 ; 1 = pressed 79 | move.w (a1), d1 ; get previous joypad state 80 | eor.w d0, d1 ; diff current with previous 81 | move.w d0, (a1)+ ; store current joypad state 82 | and.w d0, d1 83 | move.w d1, (a1)+ ; store held joypad state 84 | rts 85 | ;}****************************************************************** 86 | -------------------------------------------------------------------------------- /04-PatternsIntro/sys/sysMacros.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; SYSTEM MACROS 3 | ;{****************************************************************** 4 | ; 5 | ; Title: sysMacros.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; Z80 Reset 32 | ;{****************************************************************** 33 | Z80Reset_m MACRO 34 | move.w #0x0000, CTRL_Z80RESET 35 | exg.l a0,a1 ; waste some time 36 | exg.l a1,a0 37 | move.w #0x0100, CTRL_Z80RESET 38 | ENDM 39 | ;}****************************************************************** 40 | 41 | ; ****************************************************************** 42 | ; Z80 Bus Resquest 43 | ;{****************************************************************** 44 | Z80Request_m MACRO 45 | move.w #0x0100, CTRL_Z80BUSREQ 46 | .Wait\? 47 | btst.b #0, CTRL_Z80BUSREQ 48 | bne.s .Wait\? 49 | ENDM 50 | ;}****************************************************************** 51 | 52 | ; ****************************************************************** 53 | ; Z80 Bus Release 54 | ;{****************************************************************** 55 | Z80Release_m MACRO 56 | move.w #0x0000, CTRL_Z80BUSREQ 57 | ENDM 58 | ;}****************************************************************** 59 | 60 | ; ****************************************************************** 61 | ; Synchronize to System Vint 62 | ;{****************************************************************** 63 | sysMacSyncVint_m MACRO 64 | lea intflags, a0 ; A0 points to intflags 65 | .syncVint\? 66 | btst #1, (a0) ; test if a Vertical Interrupt occured 67 | beq.s .syncVint\? ; wait until vint occurs, bit0 set = vint has happened 68 | bclr #1, (a0) ; clear the intflag 69 | ENDM 70 | ;}****************************************************************** 71 | 72 | ; ****************************************************************** 73 | ; Wait for Vertical Blanking Start 74 | ;{****************************************************************** 75 | WaitVBlankStart_m MACRO 76 | .Wait\? 77 | move.w VDP_CTRL, d0 ; Move VDP status word to d0 78 | andi.w #0x0008, d0 ; AND with bit 4 (vblank), result in status register 79 | bne.s .Wait\? ; Branch if not equal (to zero) 80 | ENDM 81 | ;}****************************************************************** 82 | 83 | ; ****************************************************************** 84 | ; Wait for Vertical Blanking End 85 | ;{****************************************************************** 86 | WaitVBlankEnd_m MACRO 87 | .Wait\? 88 | move.w VDP_CTRL, d0 ; Move VDP status word to d0 89 | andi.w #0x0008, d0 ; AND with bit 4 (vblank), result in status register 90 | beq.s .Wait\? ; Branch if equal (to zero) 91 | ENDM 92 | ;}****************************************************************** 93 | 94 | ; ****************************************************************** 95 | ; Wait for DMA End 96 | ;{****************************************************************** 97 | WaitDMAEnd_m MACRO 98 | .Wait\? 99 | lea VDP_CTRL, a0 ; a0 points to VDP control port 100 | move.w (a0), d0 ; Move VDP status word to d0 101 | andi.w #0x0002, d0 ; AND with bit 2 (dma), result in status register 102 | bne.s .Wait\? ; Branch if not equal (to zero) 103 | ENDM 104 | ;}****************************************************************** 105 | -------------------------------------------------------------------------------- /04-PatternsIntro/sys/sysRAM.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; SYSTEM RAM 3 | ;{****************************************************************** 4 | ; 5 | ; Title: sysRAM.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; Soft Interrupt Vectors 32 | ;{****************************************************************** 33 | _RAMVECTORSBASE EQU 0xFFFF00 34 | vintvector EQU _RAMVECTORSBASE+0 35 | hintvector EQU _RAMVECTORSBASE+4 36 | xintvector EQU _RAMVECTORSBASE+8 37 | intflags EQU _RAMVECTORSBASE+12 38 | _SIZEOFRAMVECTORS EQU 16 39 | 40 | ; ****************************************************************** 41 | ; Joypads 42 | ;{****************************************************************** 43 | _RAMJOYSTATEBASE EQU _RAMVECTORSBASE + _SIZEOFRAMVECTORS 44 | v_joy1State EQU _RAMJOYSTATEBASE+0 45 | v_joy1Held EQU _RAMJOYSTATEBASE+2 46 | v_joy2State EQU _RAMJOYSTATEBASE+4 47 | v_joy2Held EQU _RAMJOYSTATEBASE+6 48 | _SIZEOFRAMJOY EQU 8 49 | 50 | ; ****************************************************************** 51 | ; System Timing Variables 52 | ;{****************************************************************** 53 | _SYSTIMINGBASE EQU _RAMJOYSTATEBASE + _SIZEOFRAMJOY 54 | sysmillisinc EQU _SYSTIMINGBASE+0 55 | sysframecnt EQU _SYSTIMINGBASE+2 56 | 57 | -------------------------------------------------------------------------------- /04-PatternsIntro/tutorial04.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; TUTORIAL 04 3 | ;{****************************************************************** 4 | ; 5 | ; Title: tutorial04.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; Tutorial 04 Entry Point 32 | ;{****************************************************************** 33 | Tutorial04Entry: 34 | 35 | lea VDP_CTRL, a5 ; point to VDP port throughout 36 | lea VDP_DATA, a6 37 | 38 | ; load palettes to VDP 39 | lea Palettes, a0 ; a0 points to palettes 40 | move.w #(32-1), d0 ; 64 palette entries to write, as 32 longs 41 | move.w #0x8F02,(a5) ; Set autoincrement to 2 bytes 42 | move.l #VDP_CRAM_WRITE, (a5) ; VDP write to CRAM address 0x00 43 | .PalLoop 44 | move.l (a0)+, (a6) ; write 2 palette entries 45 | dbra d0, .PalLoop 46 | 47 | ; load 2 patterns to VDP, starting at pattern 1 leaving pattern 0 blank 48 | lea Pattern0, a0 ; I know, a0 already is pointing here 49 | move.w #(16-1), d0 ; 8 longs per pattern 50 | move.l #(VDP_VRAM_WRITE + (0x0020<<16)), (a5) 51 | .PatLoop 52 | move.l (a0)+, (a6) ; write patterns 53 | dbra d0, .PatLoop 54 | 55 | ; place patterns on plane A base 0xC000 (i.e. first line) 56 | lea MapTable1, a0 ; point a0 to map table 57 | move.w #(((MapTableEnd1-MapTable1)/2)-1), d0 58 | move.l #(VDP_VRAM_WRITE + (0x0003)), (a5) 59 | .MapLoop 60 | move.l (a0)+, (a6) ; write to VRAM 61 | dbra d0, .MapLoop 62 | 63 | ; place same patterns on plane A 2 lines lower (128 * linenum) 64 | ; reasoning is that the nametable is 64 patterns wide horizontally 65 | ; each nametable entry is 1 word, thus, 128 bytes per horizontal nametable line 66 | lea MapTable1, a0 67 | move.w #(((MapTableEnd1-MapTable1)/2)-1), d0 68 | move.l #(VDP_VRAM_WRITE + (0x0003) + (128*(2<<16)) ), (a5) 69 | .MapLoop2 70 | move.l (a0)+, (a6) ; write to VRAM 71 | dbra d0, .MapLoop2 72 | 73 | ; place same patterns on plane A 4 lines lower (128 * linenum) and offset 8 patterns 74 | lea MapTable1, a0 75 | move.w #(((MapTableEnd1-MapTable1)/2)-1), d0 76 | move.l #(VDP_VRAM_WRITE + (0x0003) + (128*(4<<16) + (8*(2<<16)) ) ), (a5) 77 | .MapLoop3 78 | move.l (a0)+, (a6) ; write to VRAM 79 | dbra d0, .MapLoop3 80 | 81 | ; enable display and vint 82 | move.w #0x8164, (a5) 83 | 84 | Loop: 85 | sysMacSyncVint_m ; sync to vint 86 | bra.s Loop 87 | 88 | ;}****************************************************************** 89 | 90 | Align 16 91 | MapTable1: 92 | dc.w (NT_PRI1 + NT_PAL0 + 1) ; pattern 1, pal 0 93 | dc.w (NT_PRI1 + NT_PAL1 + NT_HF + 1) ; pattern 1, hflip, pal 1 94 | dc.w (NT_PRI1 + NT_PAL2 + NT_VF + 1) ; pattern 1, vflip, pal 2 95 | dc.w (NT_PRI1 + NT_PAL3 + NT_VF + NT_HF + 1) ; pattern 1, hvflip, pal 3 96 | dc.w (NT_PRI1 + NT_PAL0 + 2) ; pattern 2, pal 0 97 | dc.w (NT_PRI1 + NT_PAL1 + NT_HF + 2) ; pattern 2, hflip, pal 1 98 | dc.w (NT_PRI1 + NT_PAL2 + NT_VF + 2) ; pattern 2, vflip, pal 2 99 | dc.w (NT_PRI1 + NT_PAL3 + NT_VF + NT_HF + 2) ; pattern 2, hvflip, pal 3 100 | MapTableEnd1: 101 | 102 | Align 16 103 | Palettes: 104 | PaletteRed: ;BGR 105 | dc.w 0x0000 ; transparent 106 | dc.w 0x000E ; red 0b1110 107 | dc.w 0x000A ; less red 0b1010 108 | dc.w 0x0004 ; lesser red 0b0100 109 | dc.w 0x0000 110 | dc.w 0x0000 111 | dc.w 0x0000 112 | dc.w 0x0000 113 | dc.w 0x0000 114 | dc.w 0x0000 115 | dc.w 0x0000 116 | dc.w 0x0000 117 | dc.w 0x0000 118 | dc.w 0x0000 119 | dc.w 0x0000 120 | dc.w 0x0000 121 | 122 | PaletteGreen: ;BGR 123 | dc.w 0x0000 ; transparent 124 | dc.w 0x00E0 ; green 125 | dc.w 0x00A0 ; less green 126 | dc.w 0x0040 ; lesser green 127 | dc.w 0x0000 128 | dc.w 0x0000 129 | dc.w 0x0000 130 | dc.w 0x0000 131 | dc.w 0x0000 132 | dc.w 0x0000 133 | dc.w 0x0000 134 | dc.w 0x0000 135 | dc.w 0x0000 136 | dc.w 0x0000 137 | dc.w 0x0000 138 | dc.w 0x0000 139 | 140 | PaletteBlue: ;BGR 141 | dc.w 0x0000 ; transparent 142 | dc.w 0x0E00 ; blue 143 | dc.w 0x0A00 ; less blue 144 | dc.w 0x0400 ; lesser blue 145 | dc.w 0x0000 146 | dc.w 0x0000 147 | dc.w 0x0000 148 | dc.w 0x0000 149 | dc.w 0x0000 150 | dc.w 0x0000 151 | dc.w 0x0000 152 | dc.w 0x0000 153 | dc.w 0x0000 154 | dc.w 0x0000 155 | dc.w 0x0000 156 | dc.w 0x0000 157 | 158 | PaletteWhite: ;BGR 159 | dc.w 0x0000 ; transparent 160 | dc.w 0x0EEE ; white 161 | dc.w 0x0AAA ; less white 162 | dc.w 0x0444 ; lesser white 163 | dc.w 0x0000 164 | dc.w 0x0000 165 | dc.w 0x0000 166 | dc.w 0x0000 167 | dc.w 0x0000 168 | dc.w 0x0000 169 | dc.w 0x0000 170 | dc.w 0x0000 171 | dc.w 0x0000 172 | dc.w 0x0000 173 | dc.w 0x0000 174 | dc.w 0x0000 175 | 176 | Align 16 177 | Pattern0: 178 | dc.l 0x00000000 179 | dc.l 0x00000010 180 | dc.l 0x00000010 181 | dc.l 0x00111110 182 | dc.l 0x01000010 183 | dc.l 0x01000110 184 | dc.l 0x00111010 185 | dc.l 0x00000000 186 | 187 | Pattern1: 188 | dc.l 0x00000000 189 | dc.l 0x33000000 190 | dc.l 0x22330000 191 | dc.l 0x11223300 192 | dc.l 0x00112233 193 | dc.l 0x00001122 194 | dc.l 0x00000011 195 | dc.l 0x00000000 196 | 197 | -------------------------------------------------------------------------------- /05-Fonts/.gitignore: -------------------------------------------------------------------------------- 1 | *.bin 2 | *.lst 3 | -------------------------------------------------------------------------------- /05-Fonts/05-Fonts.geany: -------------------------------------------------------------------------------- 1 | [file_prefs] 2 | final_new_line=true 3 | ensure_convert_new_lines=false 4 | strip_trailing_spaces=false 5 | replace_tabs=false 6 | 7 | [indentation] 8 | indent_width=4 9 | indent_type=1 10 | indent_hard_tab_width=8 11 | detect_indent=false 12 | detect_indent_width=false 13 | indent_mode=2 14 | 15 | [project] 16 | name=05-Fonts 17 | base_path=/home/rene/Git/68kTutorials/05-Fonts 18 | description= 19 | 20 | [long line marker] 21 | long_line_behaviour=1 22 | long_line_column=72 23 | 24 | [files] 25 | current_page=2 26 | FILE_NAME_0=5546;68k;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F05-Fonts%2Fheader.68k;0;4 27 | FILE_NAME_1=1303;68k;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F05-Fonts%2Fmain.68k;0;4 28 | FILE_NAME_2=3281;68k;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F05-Fonts%2Ftutorial05.68k;0;4 29 | FILE_NAME_3=1045;68k;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F05-Fonts%2Fsys%2Ffont%2FsysFont.68k;0;4 30 | FILE_NAME_4=5530;68k;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F05-Fonts%2Fsys%2FsysInit.68k;0;4 31 | FILE_NAME_5=1309;68k;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F05-Fonts%2Fsys%2FsysMacros.68k;0;4 32 | 33 | [editor] 34 | line_wrapping=false 35 | line_break_column=72 36 | auto_continue_multiline=true 37 | 38 | [VTE] 39 | last_dir=/home/rene/Git/Python/dbDumper-Interface 40 | -------------------------------------------------------------------------------- /05-Fonts/README.MD: -------------------------------------------------------------------------------- 1 | #Tutorial 05 - Fonts and decoding ASCII Characters 2 | -------------------------------------------------------------------------------- /05-Fonts/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ************************************ 3 | # Title 4 | # ************************************ 5 | # 6 | # Title: build.sh 7 | # Author: René Richard 8 | # Description: 9 | # 10 | # LICENSE 11 | # 12 | # This file is part of 68kTutorials. 13 | # 68kTutorials is free software: you can redistribute it and/or modify 14 | # it under the terms of the GNU General Public License as published by 15 | # the Free Software Foundation, either version 3 of the License, or 16 | # (at your option) any later version. 17 | # Foobar is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | # GNU General Public License for more details. 21 | # You should have received a copy of the GNU General Public License 22 | # along with 68kTutorials. If not, see . 23 | # 24 | # A POSIX variable 25 | OPTIND=1 # Reset in case getopts has been used previously in the shell. 26 | 27 | # clean the /out directory if it already exists 28 | if test -d out 29 | then 30 | echo "cleaning out directory" 31 | rm -r out/* 32 | else 33 | mkdir out 34 | fi 35 | 36 | # assemble main.asm 37 | asmx -C 68000 -e -w -b 0 -l out/rom.lst -o out/rom.bin -- main.68k 38 | 39 | # check for options 40 | while getopts ":d" opt; do 41 | case "$opt" in 42 | d) 43 | echo "debug selected - starting mess" >&2 44 | gnome-terminal -e "/home/rene/Dev/blastem64-0.5.1/blastem -d out/rom.bin" 45 | #mess genesis -cart out/rom.bin -debug 46 | ;; 47 | \?) 48 | echo "Invalid Option: -$OPTARG" >&2 49 | ;; 50 | esac 51 | done 52 | 53 | # Shift off the options and optional --. 54 | shift "$((OPTIND-1))" 55 | -------------------------------------------------------------------------------- /05-Fonts/header.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; ROM HEADER 3 | ;{****************************************************************** 4 | ; 5 | ; Title: header.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; 68000 Vector Table 32 | ;{****************************************************************** 33 | dc.l 0x00FFFF00 ; Initial stack pointer value 34 | dc.l EntryPoint ; Start of program 35 | dc.l Exception ; Bus error 36 | dc.l Exception ; Address error 37 | dc.l Exception ; Illegal instruction 38 | dc.l Exception ; Division by zero 39 | dc.l Exception ; CHK exception 40 | dc.l Exception ; TRAPV exception 41 | dc.l Exception ; Privilege violation 42 | dc.l Exception ; TRACE exception 43 | dc.l Exception ; Line-A emulator 44 | dc.l Exception ; Line-F emulator 45 | dc.l Exception ; Unused (reserved) 46 | dc.l Exception ; Unused (reserved) 47 | dc.l Exception ; Unused (reserved) 48 | dc.l Exception ; Unused (reserved) 49 | dc.l Exception ; Unused (reserved) 50 | dc.l Exception ; Unused (reserved) 51 | dc.l Exception ; Unused (reserved) 52 | dc.l Exception ; Unused (reserved) 53 | dc.l Exception ; Unused (reserved) 54 | dc.l Exception ; Unused (reserved) 55 | dc.l Exception ; Unused (reserved) 56 | dc.l Exception ; Unused (reserved) 57 | dc.l Exception ; Spurious exception 58 | dc.l Exception ; IRQ level 1 59 | dc.l ExtInterrupt ; IRQ level 2 (external interrupt) 60 | dc.l Exception ; IRQ level 3 61 | dc.l HBlankInterrupt ; IRQ level 4 (horizontal retrace interrupt) 62 | dc.l Exception ; IRQ level 5 63 | dc.l VBlankInterrupt ; IRQ level 6 (vertical retrace interrupt) 64 | dc.l Exception ; IRQ level 7 65 | dc.l Exception ; TRAP #00 exception 66 | dc.l Exception ; TRAP #01 exception 67 | dc.l Exception ; TRAP #02 exception 68 | dc.l Exception ; TRAP #03 exception 69 | dc.l Exception ; TRAP #04 exception 70 | dc.l Exception ; TRAP #05 exception 71 | dc.l Exception ; TRAP #06 exception 72 | dc.l Exception ; TRAP #07 exception 73 | dc.l Exception ; TRAP #08 exception 74 | dc.l Exception ; TRAP #09 exception 75 | dc.l Exception ; TRAP #10 exception 76 | dc.l Exception ; TRAP #11 exception 77 | dc.l Exception ; TRAP #12 exception 78 | dc.l Exception ; TRAP #13 exception 79 | dc.l Exception ; TRAP #14 exception 80 | dc.l Exception ; TRAP #15 exception 81 | dc.l Exception ; Unused (reserved) 82 | dc.l Exception ; Unused (reserved) 83 | dc.l Exception ; Unused (reserved) 84 | dc.l Exception ; Unused (reserved) 85 | dc.l Exception ; Unused (reserved) 86 | dc.l Exception ; Unused (reserved) 87 | dc.l Exception ; Unused (reserved) 88 | dc.l Exception ; Unused (reserved) 89 | dc.l Exception ; Unused (reserved) 90 | dc.l Exception ; Unused (reserved) 91 | dc.l Exception ; Unused (reserved) 92 | dc.l Exception ; Unused (reserved) 93 | dc.l Exception ; Unused (reserved) 94 | dc.l Exception ; Unused (reserved) 95 | dc.l Exception ; Unused (reserved) 96 | dc.l Exception ; Unused (reserved) 97 | ;}****************************************************************** 98 | 99 | ; ****************************************************************** 100 | ; Genesis ROM Info 101 | ;{****************************************************************** 102 | ; size 012345678901234567890123456789012345678901234567 103 | dc.b "SEGA GENESIS " ; Console name - 16 104 | dc.b "(C)db 2016.MAR" ; Copyright holder and release date - 16 105 | dc.b "DB FONTS AND ASCII TUTORIAL " ; Domestic name - 48 106 | dc.b "DB FONTS AND ASCII TUTORIAL " ; International name - 48 107 | dc.b "GM INTUTORL-05" ; Version number - 48 108 | dc.w 0x1234 ; Checksum 109 | dc.b "J " ; I/O support - 16 110 | dc.l 0x00000000 ; Start address of ROM 111 | dc.l __end ; End address of ROM 112 | dc.l 0x00FF0000 ; Start address of RAM 113 | dc.l 0x00FFFFFF ; End address of RAM 114 | dc.l 0x00000000 ; SRAM enabled 115 | dc.l 0x00000000 ; Unused 116 | dc.l 0x00000000 ; Start address of SRAM 117 | dc.l 0x00000000 ; End address of SRAM 118 | dc.l 0x00000000 ; Unused 119 | dc.l 0x00000000 ; Unused 120 | dc.b " " ; Notes (unused) 121 | dc.b "JUE " ; Country codes 122 | ;}****************************************************************** 123 | -------------------------------------------------------------------------------- /05-Fonts/main.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; MAIN 3 | ;{****************************************************************** 4 | ; 5 | ; Title: main.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; ASSEMBLER OPTIONS 32 | ;{****************************************************************** 33 | LIST MACRO 34 | LIST NOSYM 35 | LIST NOTEMP 36 | ;}****************************************************************** 37 | 38 | ; ****************************************************************** 39 | ; System Defines 40 | ;{****************************************************************** 41 | include 'sys/sysDef.68k' 42 | include 'sys/sysRAM.68k' 43 | ;}****************************************************************** 44 | 45 | ; ****************************************************************** 46 | ; Macros 47 | ;{****************************************************************** 48 | include 'sys/sysMacros.68k' 49 | ;}****************************************************************** 50 | 51 | ; ****************************************************************** 52 | ; Header, Startup and System Global Code 53 | ;{****************************************************************** 54 | include 'header.68k' 55 | include 'sys/sysInit.68k' 56 | include 'sys/sysInterrupts.68k' 57 | include 'sys/sysJoypad.68k' 58 | include 'sys/font/sysFont.68k' 59 | ;}****************************************************************** 60 | 61 | ; ****************************************************************** 62 | ; User Program 63 | ;{****************************************************************** 64 | __main: 65 | include 'tutorial05.68k' 66 | __end: 67 | ;}****************************************************************** 68 | 69 | -------------------------------------------------------------------------------- /05-Fonts/sys/font/8x8font.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/db-electronics/68kTutorials/51381ff2ebda391e76554bbea4c307b2e94648ef/05-Fonts/sys/font/8x8font.gif -------------------------------------------------------------------------------- /05-Fonts/sys/font/8x8font.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/db-electronics/68kTutorials/51381ff2ebda391e76554bbea4c307b2e94648ef/05-Fonts/sys/font/8x8font.xcf -------------------------------------------------------------------------------- /05-Fonts/sys/font/sys8x8font.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/db-electronics/68kTutorials/51381ff2ebda391e76554bbea4c307b2e94648ef/05-Fonts/sys/font/sys8x8font.png -------------------------------------------------------------------------------- /05-Fonts/sys/font/sysFont.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; FONT 3 | ;{****************************************************************** 4 | ; 5 | ; Title: sysFont.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; 64 Font Tiles mapped as follows, loaded at VRAM address 0 31 | ; 0 1 2 3 4 5 6 7 8 9 A B C D E F 32 | ;0 ! " # $ % & ' ( ) * + , - . / 33 | ;1 0 1 2 3 4 5 6 7 8 9 : ; < = > ? 34 | ;2 @ A B C D E F G H I J K L M N O 35 | ;3 P Q R S T U V W X Y Z [ \ ] ^ _ 36 | 37 | ; just substract 0x20 from each ascii char and ensure they are within 0x20 to 0x5F 38 | 39 | ; ****************************************************************** 40 | ; Draw Text on Plane A: 41 | ; a0 - start address of string to write 42 | ; d0 - xypos 43 | ; d1 - palette 44 | ;{****************************************************************** 45 | sysDrawTextPlaneA: 46 | 47 | ; figure out address in VRAM, put in d2 48 | ; 64x by 32y 49 | ; 128 bytes per line, 2 bytes per column 50 | ; VRAM address = Plane A base + (128*y) + (2*x) 51 | 52 | ; y pos 53 | moveq #0, d2 54 | move.w d0, d2 ; move y pos to d3 55 | lsl.w #7, d2 ; y * 128 56 | 57 | ; x pos 58 | clr.w d0 ; clear lower word 59 | swap d0 ; move x pos to lower word 60 | lsl.w #1, d0 ; x * 2 61 | 62 | ; add both offsets + VRAM base address 63 | add.w d2, d0 ; add x and y offsets 64 | swap d0 ; shift up 16 bits 65 | ori.l #(VDP_VRAM_WRITE + (0x0003)), d0 ; add in 0xC000 offset for VRAM write 66 | 67 | ; write string starting address to VDP 68 | move.l d0, (a5) 69 | 70 | ; adjust palette in d1, palette specified in bits 14 and 13 of tile map 71 | ; 0b 0000 0000 0000 00pp - input to d1, palette # in bits 0 and 1 72 | ; 0b 0pp0 0000 0000 0000 - after ror.w #3, 73 | ror.w #3, d1 ; move palette bits to 14, 13 74 | ori.w #0x8000, d1 ; set the priority bit 75 | 76 | ; write string tiles #s to VRAM until null terminator 77 | move.w #0x20, d2 ; ascii offset optimized in d2 78 | move.w #0x40, d3 ; ascii charset size optimized in d3 79 | 80 | .writeLoop 81 | moveq #0, d0 82 | move.b (a0)+, d0 ; get next char 83 | beq.s .done ; done if null character 84 | sub.b d2, d0 ; substract ascii offset 85 | blt.s .outOfRange ; display blank char if ascii less than 0x20 86 | cmp.b d3, d0 ; if ascii is greater than 0x60 (already sub's 0x20) 87 | bge.s .outOfRange ; display blank char if ascii ge to 0x60 88 | add.w d1, d0 ; add palette # to tile number 89 | move.w d0, (a6) ; write tile entry to VDP 90 | bra.s .writeLoop 91 | .outOfRange 92 | move.w #0x1F, (a6) ; write '?' char for out of range ascii 93 | .done 94 | rts 95 | 96 | ;}****************************************************************** 97 | 98 | 99 | ; ****************************************************************** 100 | ; Load Font 101 | ;{****************************************************************** 102 | sysLoadFontPatterns: 103 | lea sysFontData, a0 ; point a0 to font data 104 | move.w #( (sysFontDataEnd-sysFontData)/4 - 1 ), d0 ; size in longs of font data 105 | move.l #VDP_VRAM_WRITE, (a5) ; font data loaded at VRAM addr 0x0000 106 | .loop 107 | move.l (a0)+, (a6) ; write patterns 108 | dbra d0, .loop 109 | rts 110 | ;}****************************************************************** 111 | 112 | Align 16 113 | sysFontData: 114 | dc.b 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 115 | dc.b 0,17,17,0,0,17,17,0,0,17,17,0,0,17,17,0,0,17,17,0,0,0,0,0,0,17,17,0,0,0,0,0 116 | dc.b 0,0,0,0,0,16,17,0,0,16,17,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 117 | dc.b 0,17,1,16,0,17,1,16,1,17,17,17,0,17,1,16,1,17,17,17,0,17,1,16,0,17,1,16,0,0,0,0 118 | dc.b 0,0,0,0,0,0,16,0,0,0,17,17,0,1,17,0,0,1,17,0,0,1,17,0,17,17,16,0,0,0,16,0 119 | dc.b 0,0,0,0,0,0,0,0,1,16,1,16,1,16,17,0,0,1,16,0,0,17,1,16,1,16,1,16,0,0,0,0 120 | dc.b 0,0,0,0,0,17,16,0,1,16,17,0,0,17,16,0,1,17,16,0,1,16,17,0,1,16,1,17,0,17,16,0 121 | dc.b 0,0,17,0,0,1,16,0,0,17,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 122 | dc.b 0,0,0,0,0,1,17,16,0,17,0,0,0,17,0,0,0,17,0,0,0,17,0,0,0,17,0,0,0,1,17,16 123 | dc.b 0,0,0,0,1,17,16,0,0,0,17,0,0,0,17,0,0,0,17,0,0,0,17,0,0,0,17,0,1,17,16,0 124 | dc.b 0,0,0,0,0,0,0,0,0,17,1,16,0,1,17,0,1,17,17,17,0,1,17,0,0,17,1,16,0,0,0,0 125 | dc.b 0,0,0,0,0,0,0,0,0,1,16,0,0,1,16,0,1,17,17,16,0,1,16,0,0,1,16,0,0,0,0,0 126 | dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,16,0,0,1,16,0,0,1,0,0 127 | dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,17,17,17,0,0,0,0,0,0,0,0,0,0,0,0 128 | dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,16,0,0,1,16,0,0,0,0,0 129 | dc.b 0,0,0,0,0,0,0,0,0,0,1,16,0,0,17,0,0,1,16,0,0,17,0,0,1,16,0,0,0,0,0,0 130 | dc.b 0,0,0,0,0,0,0,0,1,17,17,17,1,17,0,17,1,17,0,17,1,17,0,17,1,17,17,17,0,0,0,0 131 | dc.b 0,0,0,0,0,0,0,0,1,17,17,0,0,1,17,0,0,1,17,0,0,1,17,0,0,17,17,16,0,0,0,0 132 | dc.b 0,0,0,0,0,0,0,0,1,17,17,17,0,0,0,17,1,17,17,17,1,17,0,0,1,17,17,17,0,0,0,0 133 | dc.b 0,0,0,0,0,0,0,0,1,17,17,17,0,0,1,17,1,17,17,17,0,0,1,17,1,17,17,17,0,0,0,0 134 | dc.b 0,0,0,0,1,17,0,0,1,17,0,0,1,17,1,16,1,17,17,17,0,0,1,16,0,0,1,16,0,0,0,0 135 | dc.b 0,0,0,0,0,0,0,0,1,17,17,17,1,17,0,0,1,17,17,17,0,0,1,17,1,17,17,17,0,0,0,0 136 | dc.b 0,0,0,0,1,17,0,0,1,17,0,0,1,17,0,0,1,17,17,17,1,17,0,17,1,17,17,17,0,0,0,0 137 | dc.b 0,0,0,0,0,0,0,0,1,17,17,17,0,0,1,17,0,0,1,17,0,0,1,17,0,0,1,17,0,0,0,0 138 | dc.b 0,0,0,0,0,0,0,0,1,17,17,17,1,17,0,17,1,17,17,17,1,17,0,17,1,17,17,17,0,0,0,0 139 | dc.b 0,0,0,0,0,0,0,0,1,17,17,17,1,16,1,17,1,17,17,17,0,0,1,17,0,0,1,17,0,0,1,17 140 | dc.b 0,0,0,0,0,0,0,0,0,1,16,0,0,1,16,0,0,0,0,0,0,1,16,0,0,1,16,0,0,0,0,0 141 | dc.b 0,0,0,0,0,0,0,0,0,1,16,0,0,1,16,0,0,0,0,0,0,1,16,0,0,1,16,0,0,17,0,0 142 | dc.b 0,0,1,16,0,0,17,0,0,1,16,0,0,17,0,0,0,1,16,0,0,0,17,0,0,0,1,16,0,0,0,0 143 | dc.b 0,0,0,0,0,0,0,0,17,17,17,17,0,0,0,0,0,0,0,0,0,0,0,0,17,17,17,17,0,0,0,0 144 | dc.b 1,16,0,0,0,17,0,0,0,1,16,0,0,0,17,0,0,1,16,0,0,17,0,0,1,16,0,0,0,0,0,0 145 | dc.b 1,17,17,0,0,0,1,16,0,1,17,16,0,1,17,0,0,1,17,0,0,0,0,0,0,1,17,0,0,0,0,0 146 | dc.b 0,0,0,0,0,0,0,0,0,17,17,16,1,17,0,1,1,17,1,17,1,17,0,0,0,17,17,17,0,0,0,0 147 | dc.b 0,0,0,0,0,0,0,0,17,17,17,17,0,0,0,17,1,17,17,17,1,17,0,17,1,17,0,17,0,0,0,0 148 | dc.b 0,0,0,0,0,0,0,0,17,17,17,16,0,0,0,17,1,17,17,16,1,17,0,17,1,17,17,16,0,0,0,0 149 | dc.b 0,0,0,0,0,0,0,0,0,17,17,17,1,17,0,0,1,17,0,0,1,17,0,0,0,17,17,17,0,0,0,0 150 | dc.b 0,0,0,0,0,0,0,0,17,17,17,16,0,0,0,17,1,17,0,17,1,17,0,17,1,17,17,16,0,0,0,0 151 | dc.b 0,0,0,0,0,0,0,0,17,17,17,17,0,0,0,0,1,17,17,17,1,17,0,0,1,17,17,17,0,0,0,0 152 | dc.b 0,0,0,0,0,0,0,0,17,17,17,17,1,17,0,0,1,17,17,17,1,17,0,0,1,17,0,0,0,0,0,0 153 | dc.b 0,0,0,0,0,0,0,0,0,17,17,17,1,17,0,0,1,17,0,17,1,17,0,17,0,17,17,17,0,0,0,0 154 | dc.b 0,0,0,0,0,0,0,0,1,17,0,17,1,17,0,17,1,17,17,17,1,17,0,17,1,17,0,17,1,17,0,0 155 | dc.b 0,0,0,0,0,0,0,0,0,1,17,0,0,1,17,0,0,1,17,0,0,1,17,0,0,1,17,0,0,0,0,0 156 | dc.b 0,0,0,0,0,0,0,0,17,17,17,17,0,0,1,17,0,0,1,17,0,0,1,17,1,17,17,17,0,0,0,0 157 | dc.b 0,0,0,0,0,0,0,0,1,17,0,17,1,17,1,16,1,17,17,0,1,17,1,16,1,17,0,17,1,17,0,0 158 | dc.b 0,0,0,0,1,17,0,0,1,17,0,0,1,17,0,0,1,17,0,0,1,17,0,0,1,17,17,17,0,0,0,0 159 | dc.b 0,0,0,0,0,0,0,0,1,16,0,17,1,17,1,17,1,17,17,17,1,16,16,17,1,16,0,17,0,0,0,0 160 | dc.b 1,0,0,0,1,16,0,0,1,17,0,17,1,17,16,17,1,17,17,17,1,17,1,17,1,17,0,17,0,0,0,1 161 | dc.b 0,0,0,0,0,0,0,0,17,17,17,16,0,0,0,17,1,17,0,17,1,17,0,17,0,17,17,16,0,0,0,0 162 | dc.b 0,0,0,0,0,0,0,0,17,17,17,16,0,0,0,17,1,17,17,16,1,17,0,0,1,17,0,0,0,0,0,0 163 | dc.b 0,0,0,0,0,0,0,0,0,17,17,16,1,17,0,17,1,17,0,17,1,17,0,17,0,17,17,16,0,0,0,17 164 | dc.b 0,0,0,0,0,0,0,0,17,17,17,16,0,0,0,17,1,17,17,16,1,17,1,16,1,17,0,17,0,0,0,0 165 | dc.b 0,0,0,0,0,0,0,0,0,0,17,17,0,1,17,0,0,1,17,0,0,1,17,0,17,17,16,0,0,0,0,0 166 | dc.b 0,0,0,0,0,0,0,0,17,17,17,17,0,1,17,0,0,1,17,0,0,1,17,0,0,1,17,0,0,0,0,0 167 | dc.b 0,0,0,0,0,0,0,0,1,17,0,17,1,17,0,17,1,17,0,17,1,17,0,17,0,17,17,16,0,0,0,0 168 | dc.b 0,0,0,0,0,0,0,0,1,17,0,17,1,17,0,17,1,17,0,17,0,17,17,16,0,1,17,0,0,0,0,0 169 | dc.b 0,0,0,0,0,0,0,17,1,16,0,17,1,16,16,17,1,17,17,17,1,17,1,17,1,16,0,17,0,0,0,0 170 | dc.b 0,0,0,0,0,0,0,0,1,17,0,17,1,17,0,17,0,17,17,16,1,17,0,17,1,17,0,17,1,17,0,0 171 | dc.b 0,0,0,0,0,0,0,0,1,17,0,17,1,17,0,17,1,17,17,17,0,1,17,0,0,1,17,0,0,1,17,0 172 | dc.b 0,0,0,0,0,0,0,0,17,17,17,17,0,0,1,17,0,17,17,16,1,17,0,0,1,17,17,17,0,0,0,0 173 | dc.b 0,0,0,0,0,0,0,0,0,1,17,17,0,1,17,0,0,1,17,0,0,1,17,0,0,1,17,17,0,0,0,0 174 | dc.b 0,0,0,0,0,0,0,0,1,16,0,0,0,17,0,0,0,1,16,0,0,0,17,0,0,0,1,16,0,0,0,0 175 | dc.b 0,0,0,0,0,0,0,0,17,17,16,0,0,17,16,0,0,17,16,0,0,17,16,0,17,17,16,0,0,0,0,0 176 | dc.b 0,1,16,0,0,17,17,0,1,16,1,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 177 | dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,17,17,17,0,0,0,0 178 | sysFontDataEnd: 179 | 180 | -------------------------------------------------------------------------------- /05-Fonts/sys/sysDef.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; SYSTEM DEFINITIONS 3 | ;{****************************************************************** 4 | ; 5 | ; Title: sysDef.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; VDP Addresses 32 | ;{****************************************************************** 33 | VDP_DATA equ 0x00C00000 34 | VDP_CTRL equ 0x00C00004 35 | VDP_HVCOUNTER equ 0x00C00008 36 | VDP_PSG equ 0x00C00011 37 | ;}****************************************************************** 38 | 39 | ; ****************************************************************** 40 | ; VDP Control Masks 41 | ;{****************************************************************** 42 | VDP_VSRAM_WRITE equ 0x40000010 43 | VDP_VSRAM_READ equ 0x00000010 44 | VDP_CRAM_WRITE equ 0xC0000000 45 | VDP_CRAM_READ equ 0x00000020 46 | VDP_VRAM_WRITE equ 0x40000000 47 | VDP_VRAM_READ equ 0x00000000 48 | 49 | NT_PRI1 equ 0x8000 50 | NT_PRI0 equ 0x0000 51 | NT_PAL0 equ 0x0000 52 | NT_PAL1 equ 0x2000 53 | NT_PAL2 equ 0x4000 54 | NT_PAL3 equ 0x6000 55 | NT_VF equ 0x1000 56 | NT_HF equ 0x0800 57 | 58 | ;}****************************************************************** 59 | 60 | ; ****************************************************************** 61 | ; I/O Addresses 62 | ;{****************************************************************** 63 | IO_VERSIONNO equ 0x00A10001 64 | IO_DATA_1 equ 0x00A10003 65 | IO_DATA_2 equ 0x00A10005 66 | IO_DATA_EXP equ 0x00A10007 67 | IO_CTRL_1 equ 0x00A10009 68 | IO_CTRL_2 equ 0x00A1000B 69 | IO_CTRL_EXP equ 0x00A1000D 70 | IO_TXDATA_1 equ 0x00A1000F 71 | IO_RXDATA_1 equ 0x00A10011 72 | IO_SCTRL_1 equ 0x00A10013 73 | IO_TXDATA_2 equ 0x00A10015 74 | IO_RXDATA_2 equ 0x00A10017 75 | IO_SCTRL_2 equ 0x00A10019 76 | IO_TXDATA_3 equ 0x00A1001B 77 | IO_RXDATA_3 equ 0x00A1001D 78 | IO_SCTRL_EXP equ 0x00A1001F 79 | ;}****************************************************************** 80 | 81 | ; ****************************************************************** 82 | ; Z80 Addresses 83 | ;{****************************************************************** 84 | Z80_MEMSPACE equ 0x00A00000 85 | Z80_RAM equ 0x00A00000 86 | ;}****************************************************************** 87 | 88 | ; ****************************************************************** 89 | ; CTRL Addresses 90 | ;{****************************************************************** 91 | CTRL_MEMMODE equ 0x00A11000 92 | CTRL_Z80BUSREQ equ 0x00A11100 93 | CTRL_Z80RESET equ 0x00A11200 94 | CTRL_TIME equ 0x00A13000 95 | CTRL_TMSS equ 0x00A14000 96 | ;}****************************************************************** 97 | 98 | ; ****************************************************************** 99 | ; Other Addresses 100 | ;{****************************************************************** 101 | M68K_RAM equ 0x00FF0000 102 | ;}****************************************************************** 103 | 104 | ; ****************************************************************** 105 | ; JOY bit numbers SACBRLDU 106 | ;{****************************************************************** 107 | JOY_UP equ 0 108 | JOY_DOWN equ 1 109 | JOY_LEFT equ 2 110 | JOY_RIGHT equ 3 111 | JOY_A equ 6 112 | JOY_B equ 4 113 | JOY_C equ 5 114 | JOY_START equ 7 115 | ;}****************************************************************** 116 | -------------------------------------------------------------------------------- /05-Fonts/sys/sysInterrupts.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; SYSTEM INTERRUPTS 3 | ;{****************************************************************** 4 | ; 5 | ; Title: sysInterrupts.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; Vertical Interrupts - Level 6 32 | ;{****************************************************************** 33 | 34 | VBlankInterrupt: 35 | addq.w #1, sysframecnt ; increment vint counter 36 | add.l sysmillisinc, d7 ; D7 = global millis counter 37 | bset #1, intflags ; set vintflag 38 | tst.l vintvector ; test vintvector 39 | beq.s .noVector ; if vintvector = 0, get out of here! 40 | .vectorValid 41 | movem.l d0-d6/a0-a6, -(sp) ; push context to stack 42 | movea.l vintvector, a0 ; put vintvector in A0 43 | jsr (a0) ; jsr to vintvector 44 | movem.l (sp)+, d0-d6/a0-a6 ; pop context from stack 45 | .noVector 46 | rte ; return to main code 47 | ;}****************************************************************** 48 | 49 | ; ****************************************************************** 50 | ; Horizontal Interrupts - Level 4 51 | ;{****************************************************************** 52 | HBlankInterrupt: 53 | bset #0, intflags ; set hintflag 54 | rte 55 | ;}****************************************************************** 56 | 57 | ; ****************************************************************** 58 | ; External Interrupts - Level 2 59 | ;{****************************************************************** 60 | ExtInterrupt: 61 | bset #2, intflags ; set xintflag 62 | rte 63 | ;}****************************************************************** 64 | 65 | ; ****************************************************************** 66 | ; Macros 67 | ;{****************************************************************** 68 | sysInt_VDPDisableHInt MACRO 69 | move.w #0x8004, VDP_CTRL 70 | ENDM 71 | 72 | sysInt_VDPEnableHInt MACRO 73 | move.w #0x8014, VDP_CTRL 74 | ENDM 75 | ;}****************************************************************** 76 | 77 | ; ****************************************************************** 78 | ; Exception 79 | ;{****************************************************************** 80 | Exception: 81 | stop #0x2700 ; Halt CPU 82 | ;}****************************************************************** 83 | -------------------------------------------------------------------------------- /05-Fonts/sys/sysJoypad.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; SYSTEM JOYPAD 3 | ;{****************************************************************** 4 | ; 5 | ; Title: sysJoypad.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; JOYPAD_ReadPad01: 32 | ; 33 | ; destroys: 34 | ; A0, A1, D5, D6 35 | ; returns: 36 | ; D6 = SACBRLDU 37 | ; joy1State (RAM) = D6 38 | ;{****************************************************************** 39 | JOYPAD_ReadPad01: 40 | lea IO_DATA_1, a0 ; load data_1 address 41 | lea v_joy1State, a1 ; point to RAM placeholder for joystate 42 | move.b (a0), d6 ; read status j1 = 00CBRLDU 43 | move.b #0x00, (a0) ; set TH low 44 | nop ; wait to settle 45 | nop ; 46 | move.b (a0), d5 ; read status = 00SA00DU 47 | rol.b #2, d5 ; SA00DU?? 48 | andi.b #0x00, d5 ; SA000000 49 | or.b d5, d6 ; D6 = SACBRLDU 50 | not.b d6 ; invert, 1 = pressed 51 | move.b #0x00, (a0) ; set TH high for next pass 52 | move.w d6, (a1) ; store to RAM 53 | rts 54 | ;}****************************************************************** 55 | 56 | ; ****************************************************************** 57 | ; sysJoy_Read3Button 58 | ; 59 | ; destroys: 60 | ; A0, A1, D0, D1 61 | ;{****************************************************************** 62 | sysJoy_Read3Button: 63 | lea IO_DATA_1, a0 ; load data_1 address 64 | lea v_joy1State, a1 ; point to RAM placeholder for joystate 65 | bsr.s .read ; 66 | addq.w #2, a0 ; 67 | 68 | .read 69 | move.b (a0), d0 ; read status of j1 = 00CBRLDU, TH already high 70 | move.b #0x00, (a0) ; set TH low 71 | nop ; wait to settle 72 | nop ; 73 | move.b (a0), d1 ; read status = 00SA00DU 74 | move.b #0x40, (a0) ; set TH high for next pass 75 | rol.b #2, d1 ; SA00DU?? 76 | andi.b #0xC0, d1 ; SA000000 77 | or.b d1, d0 ; D0.b = SACBRLDU j1 78 | not.b d0 ; 1 = pressed 79 | move.w (a1), d1 ; get previous joypad state 80 | eor.w d0, d1 ; diff current with previous 81 | move.w d0, (a1)+ ; store current joypad state 82 | and.w d0, d1 83 | move.w d1, (a1)+ ; store held joypad state 84 | rts 85 | ;}****************************************************************** 86 | -------------------------------------------------------------------------------- /05-Fonts/sys/sysMacros.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; SYSTEM MACROS 3 | ;{****************************************************************** 4 | ; 5 | ; Title: sysMacros.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; Z80 Reset 32 | ;{****************************************************************** 33 | Z80Reset_m MACRO 34 | move.w #0x0000, CTRL_Z80RESET 35 | exg.l a0,a1 ; waste some time 36 | exg.l a1,a0 37 | move.w #0x0100, CTRL_Z80RESET 38 | ENDM 39 | ;}****************************************************************** 40 | 41 | ; ****************************************************************** 42 | ; Z80 Bus Resquest 43 | ;{****************************************************************** 44 | Z80Request_m MACRO 45 | move.w #0x0100, CTRL_Z80BUSREQ 46 | .Wait\? 47 | btst.b #0, CTRL_Z80BUSREQ 48 | bne.s .Wait\? 49 | ENDM 50 | ;}****************************************************************** 51 | 52 | ; ****************************************************************** 53 | ; Z80 Bus Release 54 | ;{****************************************************************** 55 | Z80Release_m MACRO 56 | move.w #0x0000, CTRL_Z80BUSREQ 57 | ENDM 58 | ;}****************************************************************** 59 | 60 | ; ****************************************************************** 61 | ; Synchronize to System Vint 62 | ;{****************************************************************** 63 | sysMacSyncVint_m MACRO 64 | lea intflags, a0 ; A0 points to intflags 65 | .syncVint\? 66 | btst #1, (a0) ; test if a Vertical Interrupt occured 67 | beq.s .syncVint\? ; wait until vint occurs, bit0 set = vint has happened 68 | bclr #1, (a0) ; clear the intflag 69 | ENDM 70 | ;}****************************************************************** 71 | 72 | ; ****************************************************************** 73 | ; Wait for Vertical Blanking Start 74 | ;{****************************************************************** 75 | WaitVBlankStart_m MACRO 76 | .Wait\? 77 | move.w VDP_CTRL, d0 ; Move VDP status word to d0 78 | andi.w #0x0008, d0 ; AND with bit 4 (vblank), result in status register 79 | bne.s .Wait\? ; Branch if not equal (to zero) 80 | ENDM 81 | ;}****************************************************************** 82 | 83 | ; ****************************************************************** 84 | ; Wait for Vertical Blanking End 85 | ;{****************************************************************** 86 | WaitVBlankEnd_m MACRO 87 | .Wait\? 88 | move.w VDP_CTRL, d0 ; Move VDP status word to d0 89 | andi.w #0x0008, d0 ; AND with bit 4 (vblank), result in status register 90 | beq.s .Wait\? ; Branch if equal (to zero) 91 | ENDM 92 | ;}****************************************************************** 93 | 94 | ; ****************************************************************** 95 | ; Wait for DMA End 96 | ;{****************************************************************** 97 | WaitDMAEnd_m MACRO 98 | .Wait\? 99 | lea VDP_CTRL, a0 ; a0 points to VDP control port 100 | move.w (a0), d0 ; Move VDP status word to d0 101 | andi.w #0x0002, d0 ; AND with bit 2 (dma), result in status register 102 | bne.s .Wait\? ; Branch if not equal (to zero) 103 | ENDM 104 | ;}****************************************************************** 105 | -------------------------------------------------------------------------------- /05-Fonts/sys/sysRAM.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; SYSTEM RAM 3 | ;{****************************************************************** 4 | ; 5 | ; Title: sysRAM.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; Soft Interrupt Vectors 32 | ;{****************************************************************** 33 | _RAMVECTORSBASE EQU 0xFFFF00 34 | vintvector EQU _RAMVECTORSBASE+0 35 | hintvector EQU _RAMVECTORSBASE+4 36 | xintvector EQU _RAMVECTORSBASE+8 37 | intflags EQU _RAMVECTORSBASE+12 38 | _SIZEOFRAMVECTORS EQU 16 39 | 40 | ; ****************************************************************** 41 | ; Joypads 42 | ;{****************************************************************** 43 | _RAMJOYSTATEBASE EQU _RAMVECTORSBASE + _SIZEOFRAMVECTORS 44 | v_joy1State EQU _RAMJOYSTATEBASE+0 45 | v_joy1Held EQU _RAMJOYSTATEBASE+2 46 | v_joy2State EQU _RAMJOYSTATEBASE+4 47 | v_joy2Held EQU _RAMJOYSTATEBASE+6 48 | _SIZEOFRAMJOY EQU 8 49 | 50 | ; ****************************************************************** 51 | ; System Timing Variables 52 | ;{****************************************************************** 53 | _SYSTIMINGBASE EQU _RAMJOYSTATEBASE + _SIZEOFRAMJOY 54 | sysmillisinc EQU _SYSTIMINGBASE+0 55 | sysframecnt EQU _SYSTIMINGBASE+2 56 | 57 | -------------------------------------------------------------------------------- /05-Fonts/tutorial05.68k: -------------------------------------------------------------------------------- 1 | ; ************************************ 2 | ; Title 3 | ; ************************************ 4 | ; 5 | ; Title: tutorial05.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ; ************************************ 29 | ; Tutorial 05 30 | ; ************************************ 31 | Tutorial05Entry: 32 | 33 | lea VDP_CTRL, a5 ; point to VDP port throughout 34 | lea VDP_DATA, a6 35 | move.w #0x8F02, (a5) ; Set autoincrement to 2 bytes 36 | 37 | ; load font to VRAM 38 | jsr sysLoadFontPatterns ; load fonts 39 | 40 | ; load palettes to VDP 41 | lea Palettes, a0 ; a0 points to palettes 42 | moveq #(32-1), d0 ; 64 palette entries to write, as 32 longs 43 | move.l #VDP_CRAM_WRITE, (a5) ; VDP write to CRAM address 0x00 44 | .PalLoop 45 | move.l (a0)+, (a6) ; write 2 palette entries 46 | dbra d0, .PalLoop 47 | 48 | ; Draw Text on Plane A: 49 | ; a0 - start address of string to write 50 | ; d0 - xypos 51 | ; d1 - palette 52 | lea zdbString, a0 53 | move.l #( (12<<16) + (8) ), d0 ; place string at 12,8 54 | moveq #0, d1 ; use palette 0 55 | jsr sysDrawTextPlaneA 56 | 57 | lea zdbWasHere, a0 58 | move.l #( (12<<16) + (9) ), d0 ; place string at 12,9 59 | moveq #1, d1 ; use palette 1 60 | jsr sysDrawTextPlaneA 61 | 62 | lea zTestLimitChars, a0 63 | move.l #( (12<<16) + (10) ), d0 ; place string at 12,10 64 | moveq #2, d1 ; use palette 2 65 | jsr sysDrawTextPlaneA 66 | 67 | lea zdbString, a0 68 | move.l #( (12<<16) + (11) ), d0 ; place string at 12,11 69 | moveq #3, d1 ; use palette 3 70 | jsr sysDrawTextPlaneA 71 | 72 | lea zQuickBrown, a0 73 | move.l #( (9<<16) + (13) ), d0 ; place string at 3,13 74 | moveq #0, d1 ; use palette 0 75 | jsr sysDrawTextPlaneA 76 | 77 | lea zLazyDog, a0 78 | move.l #( (7<<16) + (14) ), d0 ; place string at 1,14 79 | moveq #1, d1 ; use palette 1 80 | jsr sysDrawTextPlaneA 81 | 82 | lea zAllOtherChars1, a0 83 | move.l #( (10<<16) + (16) ), d0 ; place string at 1,16 84 | moveq #2, d1 ; use palette 2 85 | jsr sysDrawTextPlaneA 86 | 87 | lea zAllOtherChars2, a0 88 | move.l #( (10<<16) + (17) ), d0 ; place string at 1,17 89 | moveq #3, d1 ; use palette 3 90 | jsr sysDrawTextPlaneA 91 | 92 | ; enable display and vint 93 | move.w #0x8164, (a5) 94 | 95 | Loop: 96 | sysMacSyncVint_m ; sync to vint 97 | bra.s Loop 98 | 99 | ;}****************************************************************** 100 | 101 | zdbString: 102 | dc.b 'DB ELECTRONICS',0 103 | zdbWasHere: 104 | dc.b 'RENE WAS HERE!',0 105 | zTestLimitChars: 106 | dc.b '__ LIMITS __',0 107 | zQuickBrown: 108 | dc.b 'THE QUICK BROWN FOX',0 109 | zLazyDog: 110 | dc.b 'JUMPS OVER THE LAZY DOG',0 111 | zAllOtherChars1: 112 | dc.b '@!"#$%&()*+,-./[]\\',0 113 | zAllOtherChars2: 114 | dc.b '0123456789:;<=>?^_',0 115 | 116 | align 16 117 | Palettes: 118 | PaletteRed: ;BGR 119 | dc.w 0x0000 ; transparent 120 | dc.w 0x000E ; red 0b1110 121 | dc.w 0x000A ; less red 0b1010 122 | dc.w 0x0004 ; lesser red 0b0100 123 | dc.w 0x0000 124 | dc.w 0x0000 125 | dc.w 0x0000 126 | dc.w 0x0000 127 | dc.w 0x0000 128 | dc.w 0x0000 129 | dc.w 0x0000 130 | dc.w 0x0000 131 | dc.w 0x0000 132 | dc.w 0x0000 133 | dc.w 0x0000 134 | dc.w 0x0000 135 | 136 | PaletteGreen: ;BGR 137 | dc.w 0x0000 ; transparent 138 | dc.w 0x00E0 ; green 139 | dc.w 0x00A0 ; less green 140 | dc.w 0x0040 ; lesser green 141 | dc.w 0x0000 142 | dc.w 0x0000 143 | dc.w 0x0000 144 | dc.w 0x0000 145 | dc.w 0x0000 146 | dc.w 0x0000 147 | dc.w 0x0000 148 | dc.w 0x0000 149 | dc.w 0x0000 150 | dc.w 0x0000 151 | dc.w 0x0000 152 | dc.w 0x0000 153 | 154 | PaletteBlue: ;BGR 155 | dc.w 0x0000 ; transparent 156 | dc.w 0x0E00 ; blue 157 | dc.w 0x0A00 ; less blue 158 | dc.w 0x0400 ; lesser blue 159 | dc.w 0x0000 160 | dc.w 0x0000 161 | dc.w 0x0000 162 | dc.w 0x0000 163 | dc.w 0x0000 164 | dc.w 0x0000 165 | dc.w 0x0000 166 | dc.w 0x0000 167 | dc.w 0x0000 168 | dc.w 0x0000 169 | dc.w 0x0000 170 | dc.w 0x0000 171 | 172 | PaletteWhite: ;BGR 173 | dc.w 0x0000 ; transparent 174 | dc.w 0x0EEE ; white 175 | dc.w 0x0AAA ; less white 176 | dc.w 0x0444 ; lesser white 177 | dc.w 0x0000 178 | dc.w 0x0000 179 | dc.w 0x0000 180 | dc.w 0x0000 181 | dc.w 0x0000 182 | dc.w 0x0000 183 | dc.w 0x0000 184 | dc.w 0x0000 185 | dc.w 0x0000 186 | dc.w 0x0000 187 | dc.w 0x0000 188 | dc.w 0x0000 189 | -------------------------------------------------------------------------------- /06-StringConversions/.gitignore: -------------------------------------------------------------------------------- 1 | *.bin 2 | *.lst 3 | -------------------------------------------------------------------------------- /06-StringConversions/06-Strings.geany: -------------------------------------------------------------------------------- 1 | [file_prefs] 2 | final_new_line=true 3 | ensure_convert_new_lines=false 4 | strip_trailing_spaces=false 5 | replace_tabs=false 6 | 7 | [indentation] 8 | indent_width=4 9 | indent_type=1 10 | indent_hard_tab_width=8 11 | detect_indent=false 12 | detect_indent_width=false 13 | indent_mode=2 14 | 15 | [project] 16 | name=06-StringConversions 17 | base_path=/home/rene/Git/68kTutorials/06-StringConversions 18 | description= 19 | 20 | [long line marker] 21 | long_line_behaviour=1 22 | long_line_column=72 23 | 24 | [files] 25 | current_page=1 26 | FILE_NAME_0=2421;68k;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F06-StringConversions%2Ftutorial06.68k;0;4 27 | FILE_NAME_1=2216;68k;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F06-StringConversions%2Fmain.68k;0;4 28 | FILE_NAME_2=2742;68k;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F06-StringConversions%2Fsys%2Ffont%2FsysFont.68k;0;4 29 | FILE_NAME_3=3671;68k;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F06-StringConversions%2Fsys%2FsysDef.68k;0;4 30 | FILE_NAME_4=2635;68k;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F06-StringConversions%2Fsys%2Fstrings%2FsysStrings.68k;0;4 31 | FILE_NAME_5=5616;68k;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F06-StringConversions%2Fheader.68k;0;4 32 | FILE_NAME_6=1432;Sh;0;EUTF-8;1;1;0;%2Fhome%2Frene%2FGit%2F68kTutorials%2F06-StringConversions%2Fbuild.sh;0;4 33 | 34 | [editor] 35 | line_wrapping=false 36 | line_break_column=72 37 | auto_continue_multiline=true 38 | 39 | [VTE] 40 | last_dir=/home/rene 41 | -------------------------------------------------------------------------------- /06-StringConversions/README.MD: -------------------------------------------------------------------------------- 1 | #Tutorial 06 - String Conversions 2 | -------------------------------------------------------------------------------- /06-StringConversions/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ************************************ 3 | # Title 4 | # ************************************ 5 | # 6 | # Title: build.sh 7 | # Author: René Richard 8 | # Description: 9 | # 10 | # LICENSE 11 | # 12 | # This file is part of 68kTutorials. 13 | # 68kTutorials is free software: you can redistribute it and/or modify 14 | # it under the terms of the GNU General Public License as published by 15 | # the Free Software Foundation, either version 3 of the License, or 16 | # (at your option) any later version. 17 | # Foobar is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | # GNU General Public License for more details. 21 | # You should have received a copy of the GNU General Public License 22 | # along with 68kTutorials. If not, see . 23 | # 24 | # A POSIX variable 25 | OPTIND=1 # Reset in case getopts has been used previously in the shell. 26 | 27 | # clean the /out directory if it already exists 28 | if test -d out 29 | then 30 | echo "cleaning out directory" 31 | rm -r out/* 32 | else 33 | mkdir out 34 | fi 35 | 36 | # assemble main.asm 37 | asmx -C 68000 -e -w -b 0 -l out/rom.lst -o out/rom.bin -- main.68k 38 | 39 | # check for options 40 | while getopts ":d" opt; do 41 | case "$opt" in 42 | d) 43 | echo "debug selected - starting mess" >&2 44 | mess genesis -cart out/rom.bin -debug 45 | ;; 46 | \?) 47 | echo "Invalid Option: -$OPTARG" >&2 48 | ;; 49 | esac 50 | done 51 | 52 | # Shift off the options and optional --. 53 | shift "$((OPTIND-1))" 54 | -------------------------------------------------------------------------------- /06-StringConversions/header.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; ROM HEADER 3 | ;{****************************************************************** 4 | ; 5 | ; Title: header.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; 68000 Vector Table 32 | ;{****************************************************************** 33 | dc.l 0x00FFFF00 ; Initial stack pointer value 34 | dc.l EntryPoint ; Start of program 35 | dc.l Exception ; Bus error 36 | dc.l Exception ; Address error 37 | dc.l Exception ; Illegal instruction 38 | dc.l Exception ; Division by zero 39 | dc.l Exception ; CHK exception 40 | dc.l Exception ; TRAPV exception 41 | dc.l Exception ; Privilege violation 42 | dc.l Exception ; TRACE exception 43 | dc.l Exception ; Line-A emulator 44 | dc.l Exception ; Line-F emulator 45 | dc.l Exception ; Unused (reserved) 46 | dc.l Exception ; Unused (reserved) 47 | dc.l Exception ; Unused (reserved) 48 | dc.l Exception ; Unused (reserved) 49 | dc.l Exception ; Unused (reserved) 50 | dc.l Exception ; Unused (reserved) 51 | dc.l Exception ; Unused (reserved) 52 | dc.l Exception ; Unused (reserved) 53 | dc.l Exception ; Unused (reserved) 54 | dc.l Exception ; Unused (reserved) 55 | dc.l Exception ; Unused (reserved) 56 | dc.l Exception ; Unused (reserved) 57 | dc.l Exception ; Spurious exception 58 | dc.l Exception ; IRQ level 1 59 | dc.l ExtInterrupt ; IRQ level 2 (external interrupt) 60 | dc.l Exception ; IRQ level 3 61 | dc.l HBlankInterrupt ; IRQ level 4 (horizontal retrace interrupt) 62 | dc.l Exception ; IRQ level 5 63 | dc.l VBlankInterrupt ; IRQ level 6 (vertical retrace interrupt) 64 | dc.l Exception ; IRQ level 7 65 | dc.l Exception ; TRAP #00 exception 66 | dc.l Exception ; TRAP #01 exception 67 | dc.l Exception ; TRAP #02 exception 68 | dc.l Exception ; TRAP #03 exception 69 | dc.l Exception ; TRAP #04 exception 70 | dc.l Exception ; TRAP #05 exception 71 | dc.l Exception ; TRAP #06 exception 72 | dc.l Exception ; TRAP #07 exception 73 | dc.l Exception ; TRAP #08 exception 74 | dc.l Exception ; TRAP #09 exception 75 | dc.l Exception ; TRAP #10 exception 76 | dc.l Exception ; TRAP #11 exception 77 | dc.l Exception ; TRAP #12 exception 78 | dc.l Exception ; TRAP #13 exception 79 | dc.l Exception ; TRAP #14 exception 80 | dc.l Exception ; TRAP #15 exception 81 | dc.l Exception ; Unused (reserved) 82 | dc.l Exception ; Unused (reserved) 83 | dc.l Exception ; Unused (reserved) 84 | dc.l Exception ; Unused (reserved) 85 | dc.l Exception ; Unused (reserved) 86 | dc.l Exception ; Unused (reserved) 87 | dc.l Exception ; Unused (reserved) 88 | dc.l Exception ; Unused (reserved) 89 | dc.l Exception ; Unused (reserved) 90 | dc.l Exception ; Unused (reserved) 91 | dc.l Exception ; Unused (reserved) 92 | dc.l Exception ; Unused (reserved) 93 | dc.l Exception ; Unused (reserved) 94 | dc.l Exception ; Unused (reserved) 95 | dc.l Exception ; Unused (reserved) 96 | dc.l Exception ; Unused (reserved) 97 | ;}****************************************************************** 98 | 99 | ; ****************************************************************** 100 | ; Genesis ROM Info 101 | ;{****************************************************************** 102 | ; size 012345678901234567890123456789012345678901234567 103 | dc.b "SEGA GENESIS " ; Console name - 16 104 | dc.b "(C)db 2016.MAR" ; Copyright holder and release date - 16 105 | dc.b "DB FONTS AND ASCII TUTORIAL " ; Domestic name - 48 106 | dc.b "DB FONTS AND ASCII TUTORIAL " ; International name - 48 107 | dc.b "GM INTUTORL-05" ; Version number - 48 108 | dc.w 0x1234 ; Checksum 109 | dc.b "J " ; I/O support - 16 110 | dc.l 0x00000000 ; Start address of ROM 111 | dc.l __end ; End address of ROM 112 | dc.l 0x00FF0000 ; Start address of RAM 113 | dc.l 0x00FFFFFF ; End address of RAM 114 | dc.l 0x00000000 ; SRAM enabled 115 | dc.l 0x00000000 ; Unused 116 | dc.l 0x00000000 ; Start address of SRAM 117 | dc.l 0x00000000 ; End address of SRAM 118 | dc.l 0x00000000 ; Unused 119 | dc.l 0x00000000 ; Unused 120 | dc.b " " ; Notes (unused) 121 | dc.b "JUE " ; Country codes 122 | ;}****************************************************************** 123 | -------------------------------------------------------------------------------- /06-StringConversions/main.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; MAIN 3 | ;{****************************************************************** 4 | ; 5 | ; Title: main.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; ASSEMBLER OPTIONS 32 | ;{****************************************************************** 33 | LIST MACRO 34 | LIST NOSYM 35 | LIST NOTEMP 36 | ;}****************************************************************** 37 | 38 | ; ****************************************************************** 39 | ; System Defines 40 | ;{****************************************************************** 41 | include 'sys/sysDef.68k' 42 | include 'sys/sysRAM.68k' 43 | ;}****************************************************************** 44 | 45 | ; ****************************************************************** 46 | ; Macros 47 | ;{****************************************************************** 48 | include 'sys/sysMacros.68k' 49 | ;}****************************************************************** 50 | 51 | ; ****************************************************************** 52 | ; Header, Startup and System Global Code 53 | ;{****************************************************************** 54 | include 'header.68k' 55 | include 'sys/sysInit.68k' 56 | include 'sys/sysInterrupts.68k' 57 | include 'sys/sysJoypad.68k' 58 | include 'sys/font/sysFont.68k' 59 | include 'sys/strings/sysStrings.68k' 60 | ;}****************************************************************** 61 | 62 | ; ****************************************************************** 63 | ; User Program 64 | ;{****************************************************************** 65 | __main: 66 | include 'tutorial06.68k' 67 | __end: 68 | ;}****************************************************************** 69 | 70 | -------------------------------------------------------------------------------- /06-StringConversions/sys/font/8x8font.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/db-electronics/68kTutorials/51381ff2ebda391e76554bbea4c307b2e94648ef/06-StringConversions/sys/font/8x8font.gif -------------------------------------------------------------------------------- /06-StringConversions/sys/font/8x8font.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/db-electronics/68kTutorials/51381ff2ebda391e76554bbea4c307b2e94648ef/06-StringConversions/sys/font/8x8font.xcf -------------------------------------------------------------------------------- /06-StringConversions/sys/font/sys8x8font.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/db-electronics/68kTutorials/51381ff2ebda391e76554bbea4c307b2e94648ef/06-StringConversions/sys/font/sys8x8font.png -------------------------------------------------------------------------------- /06-StringConversions/sys/font/sysFont.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; FONT 3 | ;{****************************************************************** 4 | ; 5 | ; Title: sysFont.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; 64 Font Tiles mapped as follows, loaded at VRAM address 0 31 | ; 0 1 2 3 4 5 6 7 8 9 A B C D E F 32 | ;0 ! " # $ % & ' ( ) * + , - . / 33 | ;1 0 1 2 3 4 5 6 7 8 9 : ; < = > ? 34 | ;2 @ A B C D E F G H I J K L M N O 35 | ;3 P Q R S T U V W X Y Z [ \ ] ^ _ 36 | 37 | ; just substract 0x20 from each ascii char and ensure they are within 0x20 to 0x5F 38 | 39 | ; ****************************************************************** 40 | ; Draw Text on Plane A: 41 | ; a0 - start address of string to write 42 | ; d0 - xypos 43 | ; d1 - palette 44 | ;{****************************************************************** 45 | sysDrawTextPlaneA: 46 | 47 | ; figure out address in VRAM, put in d2 48 | ; 64x by 32y 49 | ; 128 bytes per line, 2 bytes per column 50 | ; VRAM address = Plane A base + (128*y) + (2*x) 51 | 52 | ; y pos 53 | moveq #0, d2 54 | move.w d0, d2 ; move y pos to d3 55 | lsl.w #7, d2 ; y * 128 56 | 57 | ; x pos 58 | clr.w d0 ; clear lower word 59 | swap d0 ; move x pos to lower word 60 | lsl.w #1, d0 ; x * 2 61 | 62 | ; add both offsets + VRAM base address 63 | add.w d2, d0 ; add x and y offsets 64 | swap d0 ; shift up 16 bits 65 | ori.l #(VDP_VRAM_WRITE + (0x0003)), d0 ; add in 0xC000 offset for VRAM write 66 | 67 | ; write string starting address to VDP 68 | move.l d0, (a5) 69 | 70 | ; adjust palette in d1, palette specified in bits 14 and 13 of tile map 71 | ; 0b 0000 0000 0000 00pp - input to d1, palette # in bits 0 and 1 72 | ; 0b 0pp0 0000 0000 0000 - after ror.w #3, 73 | ror.w #3, d1 ; move palette bits to 14, 13 74 | ori.w #0x8000, d1 ; set the priority bit 75 | 76 | ; write string tiles #s to VRAM until null terminator 77 | move.w #0x20, d2 ; ascii offset optimized in d2 78 | move.w #0x40, d3 ; ascii charset size optimized in d3 79 | 80 | .writeLoop 81 | moveq #0, d0 82 | move.b (a0)+, d0 ; get next char 83 | beq.s .done ; done if null character 84 | sub.b d2, d0 ; substract ascii offset 85 | blt.s .outOfRange ; display blank char if ascii less than 0x20 86 | cmp.b d3, d0 ; if ascii is greater than 0x60 (already sub's 0x20) 87 | bge.s .outOfRange ; display blank char if ascii ge to 0x60 88 | add.w d1, d0 ; add palette # to tile number 89 | move.w d0, (a6) ; write tile entry to VDP 90 | bra.s .writeLoop 91 | .outOfRange 92 | move.w #0x1F, (a6) ; write '?' char for out of range ascii 93 | .done 94 | rts 95 | 96 | ;}****************************************************************** 97 | 98 | 99 | ; ****************************************************************** 100 | ; Load Font 101 | ;{****************************************************************** 102 | sysLoadFontPatterns: 103 | lea sysFontData, a0 ; point a0 to font data 104 | move.w #( (sysFontDataEnd-sysFontData)/4 - 1 ), d0 ; size in longs of font data 105 | move.l #VDP_VRAM_WRITE, (a5) ; font data loaded at VRAM addr 0x0000 106 | .loop 107 | move.l (a0)+, (a6) ; write patterns 108 | dbra d0, .loop 109 | rts 110 | ;}****************************************************************** 111 | 112 | Align 16 113 | sysFontData: 114 | dc.b 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 115 | dc.b 0,17,17,0,0,17,17,0,0,17,17,0,0,17,17,0,0,17,17,0,0,0,0,0,0,17,17,0,0,0,0,0 116 | dc.b 0,0,0,0,0,16,17,0,0,16,17,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 117 | dc.b 0,17,1,16,0,17,1,16,1,17,17,17,0,17,1,16,1,17,17,17,0,17,1,16,0,17,1,16,0,0,0,0 118 | dc.b 0,0,0,0,0,0,16,0,0,0,17,17,0,1,17,0,0,1,17,0,0,1,17,0,17,17,16,0,0,0,16,0 119 | dc.b 0,0,0,0,0,0,0,0,1,16,1,16,1,16,17,0,0,1,16,0,0,17,1,16,1,16,1,16,0,0,0,0 120 | dc.b 0,0,0,0,0,17,16,0,1,16,17,0,0,17,16,0,1,17,16,0,1,16,17,0,1,16,1,17,0,17,16,0 121 | dc.b 0,0,17,0,0,1,16,0,0,17,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 122 | dc.b 0,0,0,0,0,1,17,16,0,17,0,0,0,17,0,0,0,17,0,0,0,17,0,0,0,17,0,0,0,1,17,16 123 | dc.b 0,0,0,0,1,17,16,0,0,0,17,0,0,0,17,0,0,0,17,0,0,0,17,0,0,0,17,0,1,17,16,0 124 | dc.b 0,0,0,0,0,0,0,0,0,17,1,16,0,1,17,0,1,17,17,17,0,1,17,0,0,17,1,16,0,0,0,0 125 | dc.b 0,0,0,0,0,0,0,0,0,1,16,0,0,1,16,0,1,17,17,16,0,1,16,0,0,1,16,0,0,0,0,0 126 | dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,16,0,0,1,16,0,0,1,0,0 127 | dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,17,17,17,0,0,0,0,0,0,0,0,0,0,0,0 128 | dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,16,0,0,1,16,0,0,0,0,0 129 | dc.b 0,0,0,0,0,0,0,0,0,0,1,16,0,0,17,0,0,1,16,0,0,17,0,0,1,16,0,0,0,0,0,0 130 | dc.b 0,0,0,0,0,0,0,0,1,17,17,17,1,17,0,17,1,17,0,17,1,17,0,17,1,17,17,17,0,0,0,0 131 | dc.b 0,0,0,0,0,0,0,0,1,17,17,0,0,1,17,0,0,1,17,0,0,1,17,0,0,17,17,16,0,0,0,0 132 | dc.b 0,0,0,0,0,0,0,0,1,17,17,17,0,0,0,17,1,17,17,17,1,17,0,0,1,17,17,17,0,0,0,0 133 | dc.b 0,0,0,0,0,0,0,0,1,17,17,17,0,0,1,17,1,17,17,17,0,0,1,17,1,17,17,17,0,0,0,0 134 | dc.b 0,0,0,0,1,17,0,0,1,17,0,0,1,17,1,16,1,17,17,17,0,0,1,16,0,0,1,16,0,0,0,0 135 | dc.b 0,0,0,0,0,0,0,0,1,17,17,17,1,17,0,0,1,17,17,17,0,0,1,17,1,17,17,17,0,0,0,0 136 | dc.b 0,0,0,0,1,17,0,0,1,17,0,0,1,17,0,0,1,17,17,17,1,17,0,17,1,17,17,17,0,0,0,0 137 | dc.b 0,0,0,0,0,0,0,0,1,17,17,17,0,0,1,17,0,0,1,17,0,0,1,17,0,0,1,17,0,0,0,0 138 | dc.b 0,0,0,0,0,0,0,0,1,17,17,17,1,17,0,17,1,17,17,17,1,17,0,17,1,17,17,17,0,0,0,0 139 | dc.b 0,0,0,0,0,0,0,0,1,17,17,17,1,16,1,17,1,17,17,17,0,0,1,17,0,0,1,17,0,0,1,17 140 | dc.b 0,0,0,0,0,0,0,0,0,1,16,0,0,1,16,0,0,0,0,0,0,1,16,0,0,1,16,0,0,0,0,0 141 | dc.b 0,0,0,0,0,0,0,0,0,1,16,0,0,1,16,0,0,0,0,0,0,1,16,0,0,1,16,0,0,17,0,0 142 | dc.b 0,0,1,16,0,0,17,0,0,1,16,0,0,17,0,0,0,1,16,0,0,0,17,0,0,0,1,16,0,0,0,0 143 | dc.b 0,0,0,0,0,0,0,0,17,17,17,17,0,0,0,0,0,0,0,0,0,0,0,0,17,17,17,17,0,0,0,0 144 | dc.b 1,16,0,0,0,17,0,0,0,1,16,0,0,0,17,0,0,1,16,0,0,17,0,0,1,16,0,0,0,0,0,0 145 | dc.b 1,17,17,0,0,0,1,16,0,1,17,16,0,1,17,0,0,1,17,0,0,0,0,0,0,1,17,0,0,0,0,0 146 | dc.b 0,0,0,0,0,0,0,0,0,17,17,16,1,17,0,1,1,17,1,17,1,17,0,0,0,17,17,17,0,0,0,0 147 | dc.b 0,0,0,0,0,0,0,0,17,17,17,17,0,0,0,17,1,17,17,17,1,17,0,17,1,17,0,17,0,0,0,0 148 | dc.b 0,0,0,0,0,0,0,0,17,17,17,16,0,0,0,17,1,17,17,16,1,17,0,17,1,17,17,16,0,0,0,0 149 | dc.b 0,0,0,0,0,0,0,0,0,17,17,17,1,17,0,0,1,17,0,0,1,17,0,0,0,17,17,17,0,0,0,0 150 | dc.b 0,0,0,0,0,0,0,0,17,17,17,16,0,0,0,17,1,17,0,17,1,17,0,17,1,17,17,16,0,0,0,0 151 | dc.b 0,0,0,0,0,0,0,0,17,17,17,17,0,0,0,0,1,17,17,17,1,17,0,0,1,17,17,17,0,0,0,0 152 | dc.b 0,0,0,0,0,0,0,0,17,17,17,17,1,17,0,0,1,17,17,17,1,17,0,0,1,17,0,0,0,0,0,0 153 | dc.b 0,0,0,0,0,0,0,0,0,17,17,17,1,17,0,0,1,17,0,17,1,17,0,17,0,17,17,17,0,0,0,0 154 | dc.b 0,0,0,0,0,0,0,0,1,17,0,17,1,17,0,17,1,17,17,17,1,17,0,17,1,17,0,17,1,17,0,0 155 | dc.b 0,0,0,0,0,0,0,0,0,1,17,0,0,1,17,0,0,1,17,0,0,1,17,0,0,1,17,0,0,0,0,0 156 | dc.b 0,0,0,0,0,0,0,0,17,17,17,17,0,0,1,17,0,0,1,17,0,0,1,17,1,17,17,17,0,0,0,0 157 | dc.b 0,0,0,0,0,0,0,0,1,17,0,17,1,17,1,16,1,17,17,0,1,17,1,16,1,17,0,17,1,17,0,0 158 | dc.b 0,0,0,0,1,17,0,0,1,17,0,0,1,17,0,0,1,17,0,0,1,17,0,0,1,17,17,17,0,0,0,0 159 | dc.b 0,0,0,0,0,0,0,0,1,16,0,17,1,17,1,17,1,17,17,17,1,16,16,17,1,16,0,17,0,0,0,0 160 | dc.b 1,0,0,0,1,16,0,0,1,17,0,17,1,17,16,17,1,17,17,17,1,17,1,17,1,17,0,17,0,0,0,1 161 | dc.b 0,0,0,0,0,0,0,0,17,17,17,16,0,0,0,17,1,17,0,17,1,17,0,17,0,17,17,16,0,0,0,0 162 | dc.b 0,0,0,0,0,0,0,0,17,17,17,16,0,0,0,17,1,17,17,16,1,17,0,0,1,17,0,0,0,0,0,0 163 | dc.b 0,0,0,0,0,0,0,0,0,17,17,16,1,17,0,17,1,17,0,17,1,17,0,17,0,17,17,16,0,0,0,17 164 | dc.b 0,0,0,0,0,0,0,0,17,17,17,16,0,0,0,17,1,17,17,16,1,17,1,16,1,17,0,17,0,0,0,0 165 | dc.b 0,0,0,0,0,0,0,0,0,0,17,17,0,1,17,0,0,1,17,0,0,1,17,0,17,17,16,0,0,0,0,0 166 | dc.b 0,0,0,0,0,0,0,0,17,17,17,17,0,1,17,0,0,1,17,0,0,1,17,0,0,1,17,0,0,0,0,0 167 | dc.b 0,0,0,0,0,0,0,0,1,17,0,17,1,17,0,17,1,17,0,17,1,17,0,17,0,17,17,16,0,0,0,0 168 | dc.b 0,0,0,0,0,0,0,0,1,17,0,17,1,17,0,17,1,17,0,17,0,17,17,16,0,1,17,0,0,0,0,0 169 | dc.b 0,0,0,0,0,0,0,17,1,16,0,17,1,16,16,17,1,17,17,17,1,17,1,17,1,16,0,17,0,0,0,0 170 | dc.b 0,0,0,0,0,0,0,0,1,17,0,17,1,17,0,17,0,17,17,16,1,17,0,17,1,17,0,17,1,17,0,0 171 | dc.b 0,0,0,0,0,0,0,0,1,17,0,17,1,17,0,17,1,17,17,17,0,1,17,0,0,1,17,0,0,1,17,0 172 | dc.b 0,0,0,0,0,0,0,0,17,17,17,17,0,0,1,17,0,17,17,16,1,17,0,0,1,17,17,17,0,0,0,0 173 | dc.b 0,0,0,0,0,0,0,0,0,1,17,17,0,1,17,0,0,1,17,0,0,1,17,0,0,1,17,17,0,0,0,0 174 | dc.b 0,0,0,0,0,0,0,0,1,16,0,0,0,17,0,0,0,1,16,0,0,0,17,0,0,0,1,16,0,0,0,0 175 | dc.b 0,0,0,0,0,0,0,0,17,17,16,0,0,17,16,0,0,17,16,0,0,17,16,0,17,17,16,0,0,0,0,0 176 | dc.b 0,1,16,0,0,17,17,0,1,16,1,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 177 | dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,17,17,17,0,0,0,0 178 | sysFontDataEnd: 179 | 180 | -------------------------------------------------------------------------------- /06-StringConversions/sys/strings/sysStrings.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; SYSTEM STRINGS 3 | ;{****************************************************************** 4 | ; 5 | ; Title: sysStrings.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; Convert Word to HEX string 32 | ; d0 = word to convert 33 | ; a0 = where to store the result (4 bytes needed - 0x????) 34 | ;{****************************************************************** 35 | sysStringConvWord2Hex: 36 | moveq #0x0F, d2 ; optimize nibble mask in d2 37 | lea sysStringNumTable, a1 ; point a1 to numtable for ascii conv 38 | moveq #3-1, d3 ; repeat 3 times, unrolled last iteration 39 | .loop 40 | rol.w #4, d0 ; rotate ms nibble into lowest nibble 41 | move.w d0, d1 ; copy to d1 42 | and.w d2, d1 ; mask nibble 43 | move.b (a1,d1.w), (a0)+ ; d1 nibble is offset into StringNumTable 44 | dbra d3, .loop ; repeat 45 | .lastOne 46 | rol.w #4, d0 ; rotate 47 | and.w d2, d0 ; no need to copy last nibble 48 | move.b (a1,d0.w), (a0)+ ; last nibble 49 | clr.b (a0) ; null terminate 50 | rts 51 | 52 | ;}****************************************************************** 53 | 54 | ; ****************************************************************** 55 | ; Convert Byte to HEX string 56 | ; d0 = byte to convert 57 | ; a0 = where to store the result (2 bytes needed - 0x??) 58 | ;{****************************************************************** 59 | sysStringConvByte2Hex: 60 | moveq #0x0F, d2 ; optimize nibble mask in d2 61 | lea sysStringNumTable, a1 ; point a1 to numtable for ascii conv 62 | move.w d0, d1 ; copy to d1 63 | rol.b #4, d1 ; rotate ms nibble into lowest nibble 64 | and.w d2, d1 ; mask nibble 65 | move.b (a1,d1.w), (a0)+ ; d1 nibble is offset into StringNumTable 66 | and.w d2, d0 ; no need to copy last nibble 67 | move.b (a1,d0.w), (a0)+ ; last nibble 68 | clr.b (a0) ; null terminate 69 | rts 70 | 71 | ;}****************************************************************** 72 | 73 | sysStringNumTable: 74 | dc.b '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' 75 | -------------------------------------------------------------------------------- /06-StringConversions/sys/sysDef.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; SYSTEM DEFINITIONS 3 | ;{****************************************************************** 4 | ; 5 | ; Title: sysDef.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; VDP Addresses 32 | ;{****************************************************************** 33 | VDP_DATA equ 0x00C00000 34 | VDP_CTRL equ 0x00C00004 35 | VDP_HVCOUNTER equ 0x00C00008 36 | VDP_PSG equ 0x00C00011 37 | ;}****************************************************************** 38 | 39 | ; ****************************************************************** 40 | ; VDP Control Masks 41 | ;{****************************************************************** 42 | VDP_VSRAM_WRITE equ 0x40000010 43 | VDP_VSRAM_READ equ 0x00000010 44 | VDP_CRAM_WRITE equ 0xC0000000 45 | VDP_CRAM_READ equ 0x00000020 46 | VDP_VRAM_WRITE equ 0x40000000 47 | VDP_VRAM_READ equ 0x00000000 48 | 49 | NT_PRI1 equ 0x8000 50 | NT_PRI0 equ 0x0000 51 | NT_PAL0 equ 0x0000 52 | NT_PAL1 equ 0x2000 53 | NT_PAL2 equ 0x4000 54 | NT_PAL3 equ 0x6000 55 | NT_VF equ 0x1000 56 | NT_HF equ 0x0800 57 | 58 | ;}****************************************************************** 59 | 60 | ; ****************************************************************** 61 | ; I/O Addresses 62 | ;{****************************************************************** 63 | IO_VERSIONNO equ 0x00A10001 64 | IO_DATA_1 equ 0x00A10003 65 | IO_DATA_2 equ 0x00A10005 66 | IO_DATA_EXP equ 0x00A10007 67 | IO_CTRL_1 equ 0x00A10009 68 | IO_CTRL_2 equ 0x00A1000B 69 | IO_CTRL_EXP equ 0x00A1000D 70 | IO_TXDATA_1 equ 0x00A1000F 71 | IO_RXDATA_1 equ 0x00A10011 72 | IO_SCTRL_1 equ 0x00A10013 73 | IO_TXDATA_2 equ 0x00A10015 74 | IO_RXDATA_2 equ 0x00A10017 75 | IO_SCTRL_2 equ 0x00A10019 76 | IO_TXDATA_3 equ 0x00A1001B 77 | IO_RXDATA_3 equ 0x00A1001D 78 | IO_SCTRL_EXP equ 0x00A1001F 79 | ;}****************************************************************** 80 | 81 | ; ****************************************************************** 82 | ; Z80 Addresses 83 | ;{****************************************************************** 84 | Z80_MEMSPACE equ 0x00A00000 85 | Z80_RAM equ 0x00A00000 86 | ;}****************************************************************** 87 | 88 | ; ****************************************************************** 89 | ; CTRL Addresses 90 | ;{****************************************************************** 91 | CTRL_MEMMODE equ 0x00A11000 92 | CTRL_Z80BUSREQ equ 0x00A11100 93 | CTRL_Z80RESET equ 0x00A11200 94 | CTRL_TIME equ 0x00A13000 95 | CTRL_TMSS equ 0x00A14000 96 | ;}****************************************************************** 97 | 98 | ; ****************************************************************** 99 | ; Other Addresses 100 | ;{****************************************************************** 101 | M68K_RAM equ 0x00FF0000 102 | ;}****************************************************************** 103 | 104 | ; ****************************************************************** 105 | ; JOY bit numbers SACBRLDU 106 | ;{****************************************************************** 107 | JOY_UP equ 0 108 | JOY_DOWN equ 1 109 | JOY_LEFT equ 2 110 | JOY_RIGHT equ 3 111 | JOY_A equ 6 112 | JOY_B equ 4 113 | JOY_C equ 5 114 | JOY_START equ 7 115 | ;}****************************************************************** 116 | -------------------------------------------------------------------------------- /06-StringConversions/sys/sysInterrupts.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; SYSTEM INTERRUPTS 3 | ;{****************************************************************** 4 | ; 5 | ; Title: sysInterrupts.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; Vertical Interrupts - Level 6 32 | ;{****************************************************************** 33 | 34 | VBlankInterrupt: 35 | addq.w #1, sysframecnt ; increment vint counter 36 | add.l sysmillisinc, d7 ; D7 = global millis counter 37 | bset #1, intflags ; set vintflag 38 | tst.l vintvector ; test vintvector 39 | beq.s .noVector ; if vintvector = 0, get out of here! 40 | .vectorValid 41 | movem.l d0-d6/a0-a6, -(sp) ; push context to stack 42 | movea.l vintvector, a0 ; put vintvector in A0 43 | jsr (a0) ; jsr to vintvector 44 | movem.l (sp)+, d0-d6/a0-a6 ; pop context from stack 45 | .noVector 46 | rte ; return to main code 47 | ;}****************************************************************** 48 | 49 | ; ****************************************************************** 50 | ; Horizontal Interrupts - Level 4 51 | ;{****************************************************************** 52 | HBlankInterrupt: 53 | bset #0, intflags ; set hintflag 54 | rte 55 | ;}****************************************************************** 56 | 57 | ; ****************************************************************** 58 | ; External Interrupts - Level 2 59 | ;{****************************************************************** 60 | ExtInterrupt: 61 | bset #2, intflags ; set xintflag 62 | rte 63 | ;}****************************************************************** 64 | 65 | ; ****************************************************************** 66 | ; Macros 67 | ;{****************************************************************** 68 | sysInt_VDPDisableHInt MACRO 69 | move.w #0x8004, VDP_CTRL 70 | ENDM 71 | 72 | sysInt_VDPEnableHInt MACRO 73 | move.w #0x8014, VDP_CTRL 74 | ENDM 75 | ;}****************************************************************** 76 | 77 | ; ****************************************************************** 78 | ; Exception 79 | ;{****************************************************************** 80 | Exception: 81 | stop #0x2700 ; Halt CPU 82 | ;}****************************************************************** 83 | -------------------------------------------------------------------------------- /06-StringConversions/sys/sysJoypad.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; SYSTEM JOYPAD 3 | ;{****************************************************************** 4 | ; 5 | ; Title: sysJoypad.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; JOYPAD_ReadPad01: 32 | ; 33 | ; destroys: 34 | ; A0, A1, D5, D6 35 | ; returns: 36 | ; D6 = SACBRLDU 37 | ; joy1State (RAM) = D6 38 | ;{****************************************************************** 39 | JOYPAD_ReadPad01: 40 | lea IO_DATA_1, a0 ; load data_1 address 41 | lea v_joy1State, a1 ; point to RAM placeholder for joystate 42 | move.b (a0), d6 ; read status j1 = 00CBRLDU 43 | move.b #0x00, (a0) ; set TH low 44 | nop ; wait to settle 45 | nop ; 46 | move.b (a0), d5 ; read status = 00SA00DU 47 | rol.b #2, d5 ; SA00DU?? 48 | andi.b #0x00, d5 ; SA000000 49 | or.b d5, d6 ; D6 = SACBRLDU 50 | not.b d6 ; invert, 1 = pressed 51 | move.b #0x00, (a0) ; set TH high for next pass 52 | move.w d6, (a1) ; store to RAM 53 | rts 54 | ;}****************************************************************** 55 | 56 | ; ****************************************************************** 57 | ; sysJoy_Read3Button 58 | ; 59 | ; destroys: 60 | ; A0, A1, D0, D1 61 | ;{****************************************************************** 62 | sysJoy_Read3Button: 63 | lea IO_DATA_1, a0 ; load data_1 address 64 | lea v_joy1State, a1 ; point to RAM placeholder for joystate 65 | bsr.s .read ; 66 | addq.w #2, a0 ; 67 | 68 | .read 69 | move.b (a0), d0 ; read status of j1 = 00CBRLDU, TH already high 70 | move.b #0x00, (a0) ; set TH low 71 | nop ; wait to settle 72 | nop ; 73 | move.b (a0), d1 ; read status = 00SA00DU 74 | move.b #0x40, (a0) ; set TH high for next pass 75 | rol.b #2, d1 ; SA00DU?? 76 | andi.b #0xC0, d1 ; SA000000 77 | or.b d1, d0 ; D0.b = SACBRLDU j1 78 | not.b d0 ; 1 = pressed 79 | move.w (a1), d1 ; get previous joypad state 80 | eor.w d0, d1 ; diff current with previous 81 | move.w d0, (a1)+ ; store current joypad state 82 | and.w d0, d1 83 | move.w d1, (a1)+ ; store held joypad state 84 | rts 85 | ;}****************************************************************** 86 | -------------------------------------------------------------------------------- /06-StringConversions/sys/sysMacros.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; SYSTEM MACROS 3 | ;{****************************************************************** 4 | ; 5 | ; Title: sysMacros.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; Z80 Reset 32 | ;{****************************************************************** 33 | Z80Reset_m MACRO 34 | move.w #0x0000, CTRL_Z80RESET 35 | exg.l a0,a1 ; waste some time 36 | exg.l a1,a0 37 | move.w #0x0100, CTRL_Z80RESET 38 | ENDM 39 | ;}****************************************************************** 40 | 41 | ; ****************************************************************** 42 | ; Z80 Bus Resquest 43 | ;{****************************************************************** 44 | Z80Request_m MACRO 45 | move.w #0x0100, CTRL_Z80BUSREQ 46 | .Wait\? 47 | btst.b #0, CTRL_Z80BUSREQ 48 | bne.s .Wait\? 49 | ENDM 50 | ;}****************************************************************** 51 | 52 | ; ****************************************************************** 53 | ; Z80 Bus Release 54 | ;{****************************************************************** 55 | Z80Release_m MACRO 56 | move.w #0x0000, CTRL_Z80BUSREQ 57 | ENDM 58 | ;}****************************************************************** 59 | 60 | ; ****************************************************************** 61 | ; Synchronize to System Vint 62 | ;{****************************************************************** 63 | sysMacSyncVint_m MACRO 64 | lea intflags, a0 ; A0 points to intflags 65 | .syncVint\? 66 | btst #1, (a0) ; test if a Vertical Interrupt occured 67 | beq.s .syncVint\? ; wait until vint occurs, bit0 set = vint has happened 68 | bclr #1, (a0) ; clear the intflag 69 | ENDM 70 | ;}****************************************************************** 71 | 72 | ; ****************************************************************** 73 | ; Wait for Vertical Blanking Start 74 | ;{****************************************************************** 75 | WaitVBlankStart_m MACRO 76 | .Wait\? 77 | move.w VDP_CTRL, d0 ; Move VDP status word to d0 78 | andi.w #0x0008, d0 ; AND with bit 4 (vblank), result in status register 79 | bne.s .Wait\? ; Branch if not equal (to zero) 80 | ENDM 81 | ;}****************************************************************** 82 | 83 | ; ****************************************************************** 84 | ; Wait for Vertical Blanking End 85 | ;{****************************************************************** 86 | WaitVBlankEnd_m MACRO 87 | .Wait\? 88 | move.w VDP_CTRL, d0 ; Move VDP status word to d0 89 | andi.w #0x0008, d0 ; AND with bit 4 (vblank), result in status register 90 | beq.s .Wait\? ; Branch if equal (to zero) 91 | ENDM 92 | ;}****************************************************************** 93 | 94 | ; ****************************************************************** 95 | ; Wait for DMA End 96 | ;{****************************************************************** 97 | WaitDMAEnd_m MACRO 98 | .Wait\? 99 | lea VDP_CTRL, a0 ; a0 points to VDP control port 100 | move.w (a0), d0 ; Move VDP status word to d0 101 | andi.w #0x0002, d0 ; AND with bit 2 (dma), result in status register 102 | bne.s .Wait\? ; Branch if not equal (to zero) 103 | ENDM 104 | ;}****************************************************************** 105 | -------------------------------------------------------------------------------- /06-StringConversions/sys/sysRAM.68k: -------------------------------------------------------------------------------- 1 | ; ****************************************************************** 2 | ; SYSTEM RAM 3 | ;{****************************************************************** 4 | ; 5 | ; Title: sysRAM.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ;}****************************************************************** 29 | 30 | ; ****************************************************************** 31 | ; Soft Interrupt Vectors 32 | ;{****************************************************************** 33 | _RAMVECTORSBASE EQU 0xFFFF00 34 | vintvector EQU _RAMVECTORSBASE+0 35 | hintvector EQU _RAMVECTORSBASE+4 36 | xintvector EQU _RAMVECTORSBASE+8 37 | intflags EQU _RAMVECTORSBASE+12 38 | _SIZEOFRAMVECTORS EQU 16 39 | 40 | ; ****************************************************************** 41 | ; Joypads 42 | ;{****************************************************************** 43 | _RAMJOYSTATEBASE EQU _RAMVECTORSBASE + _SIZEOFRAMVECTORS 44 | v_joy1State EQU _RAMJOYSTATEBASE+0 45 | v_joy1Held EQU _RAMJOYSTATEBASE+2 46 | v_joy2State EQU _RAMJOYSTATEBASE+4 47 | v_joy2Held EQU _RAMJOYSTATEBASE+6 48 | _SIZEOFRAMJOY EQU 8 49 | 50 | ; ****************************************************************** 51 | ; System Timing Variables 52 | ;{****************************************************************** 53 | _SYSTIMINGBASE EQU _RAMJOYSTATEBASE + _SIZEOFRAMJOY 54 | sysmillisinc EQU _SYSTIMINGBASE+0 55 | sysframecnt EQU _SYSTIMINGBASE+2 56 | 57 | -------------------------------------------------------------------------------- /06-StringConversions/tutorial06.68k: -------------------------------------------------------------------------------- 1 | ; ************************************ 2 | ; Title 3 | ; ************************************ 4 | ; 5 | ; Title: tutorial06.68k 6 | ; Author: René Richard 7 | ; Description: 8 | ; 9 | ; Target Hardware: 10 | ; Sega Genesis / Megadrive 11 | ; Assembler: 12 | ; ASMX 13 | ; 14 | ; LICENSE 15 | ; 16 | ; This file is part of 68kTutorials. 17 | ; 68kTutorials is free software: you can redistribute it and/or modify 18 | ; it under the terms of the GNU General Public License as published by 19 | ; the Free Software Foundation, either version 3 of the License, or 20 | ; (at your option) any later version. 21 | ; 68kTutorials is distributed in the hope that it will be useful, 22 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | ; GNU General Public License for more details. 25 | ; You should have received a copy of the GNU General Public License 26 | ; along with 68kTutorials. If not, see . 27 | ; 28 | ; ************************************ 29 | ; Tutorial 06 30 | ; ************************************ 31 | Tutorial06Entry: 32 | 33 | lea VDP_CTRL, a5 ; point to VDP port throughout 34 | lea VDP_DATA, a6 35 | move.w #0x8F02, (a5) ; Set autoincrement to 2 bytes 36 | 37 | ; load font to VRAM 38 | jsr sysLoadFontPatterns ; load fonts 39 | 40 | ; load palettes to VDP 41 | lea Palettes, a0 ; a0 points to palettes 42 | moveq #(32-1), d0 ; 64 palette entries to write, as 32 longs 43 | move.l #VDP_CRAM_WRITE, (a5) ; VDP write to CRAM address 0x00 44 | .PalLoop 45 | move.l (a0)+, (a6) ; write 2 palette entries 46 | dbra d0, .PalLoop 47 | 48 | ; Convert word to ascii 49 | move.w #0xF012, d0 50 | lea M68K_RAM, a0 51 | jsr sysStringConvWord2Hex 52 | 53 | ; Draw Text on Plane A: 54 | ; a0 - start address of string to write 55 | ; d0 - xypos 56 | ; d1 - palette 57 | lea M68K_RAM, a0 58 | move.l #( (12<<16) + (8) ), d0 ; place string at 12,8 59 | moveq #0, d1 ; use palette 0 60 | jsr sysDrawTextPlaneA 61 | 62 | ; Convert byte to ascii 63 | move.b #0x5A, d0 64 | lea M68K_RAM, a0 65 | jsr sysStringConvByte2Hex 66 | 67 | ; Draw Text on Plane A: 68 | ; a0 - start address of string to write 69 | ; d0 - xypos 70 | ; d1 - palette 71 | lea M68K_RAM, a0 72 | move.l #( (12<<16) + (10) ), d0 ; place string at 12,10 73 | moveq #1, d1 ; use palette 1 74 | jsr sysDrawTextPlaneA 75 | 76 | ; enable display and vint 77 | move.w #0x8164, (a5) 78 | 79 | Loop: 80 | sysMacSyncVint_m ; sync to vint 81 | bra.s Loop 82 | 83 | ;}****************************************************************** 84 | 85 | align 16 86 | Palettes: 87 | PaletteRed: ;BGR 88 | dc.w 0x0000 ; transparent 89 | dc.w 0x000E ; red 0b1110 90 | dc.w 0x000A ; less red 0b1010 91 | dc.w 0x0004 ; lesser red 0b0100 92 | dc.w 0x0000 93 | dc.w 0x0000 94 | dc.w 0x0000 95 | dc.w 0x0000 96 | dc.w 0x0000 97 | dc.w 0x0000 98 | dc.w 0x0000 99 | dc.w 0x0000 100 | dc.w 0x0000 101 | dc.w 0x0000 102 | dc.w 0x0000 103 | dc.w 0x0000 104 | 105 | PaletteGreen: ;BGR 106 | dc.w 0x0000 ; transparent 107 | dc.w 0x00E0 ; green 108 | dc.w 0x00A0 ; less green 109 | dc.w 0x0040 ; lesser green 110 | dc.w 0x0000 111 | dc.w 0x0000 112 | dc.w 0x0000 113 | dc.w 0x0000 114 | dc.w 0x0000 115 | dc.w 0x0000 116 | dc.w 0x0000 117 | dc.w 0x0000 118 | dc.w 0x0000 119 | dc.w 0x0000 120 | dc.w 0x0000 121 | dc.w 0x0000 122 | 123 | PaletteBlue: ;BGR 124 | dc.w 0x0000 ; transparent 125 | dc.w 0x0E00 ; blue 126 | dc.w 0x0A00 ; less blue 127 | dc.w 0x0400 ; lesser blue 128 | dc.w 0x0000 129 | dc.w 0x0000 130 | dc.w 0x0000 131 | dc.w 0x0000 132 | dc.w 0x0000 133 | dc.w 0x0000 134 | dc.w 0x0000 135 | dc.w 0x0000 136 | dc.w 0x0000 137 | dc.w 0x0000 138 | dc.w 0x0000 139 | dc.w 0x0000 140 | 141 | PaletteWhite: ;BGR 142 | dc.w 0x0000 ; transparent 143 | dc.w 0x0EEE ; white 144 | dc.w 0x0AAA ; less white 145 | dc.w 0x0444 ; lesser white 146 | dc.w 0x0000 147 | dc.w 0x0000 148 | dc.w 0x0000 149 | dc.w 0x0000 150 | dc.w 0x0000 151 | dc.w 0x0000 152 | dc.w 0x0000 153 | dc.w 0x0000 154 | dc.w 0x0000 155 | dc.w 0x0000 156 | dc.w 0x0000 157 | dc.w 0x0000 158 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 68kTutorials 2 | Tutorials to teach myself 68k assembly within the context of Sega Genesis hardware... 3 | 4 | ## Inspiration 5 | Upon reading BigEvilCorporation blog posts on a similar topic I decided I would finally delve into 68k assembly. The first 6 | tutorial, HelloWorld, is more or less exactly the same as from BigEvilCorp - the only difference is that I have modified a few labels to be compatible with the ASMX assembler. I decided to go with ASMX since it supports both 68k and Z80 and can 7 | be built on Linux. 8 | 9 | ## Not For Beginners 10 | I'm not writing these tutorials for beginners. I don't assume the reader is a complete noob with respect to assembly, electronics, programming, etc... If you're a beginner in any of those categories then these tutorials are probably not for you and you should search elsewhere for beginners' guides before continuing here. I'm an electronics engineer and my main motivation for writing these is first and foremost to further my own knowledge. Think of all these tutorials as 68k lab journal of sorts. 11 | 12 | ## Format 13 | Tutorial-01 is just a compile test. From Tutorial-02 onwards I heavily modify the existing code, add my own code, and explore a few aspects of the Genesis in each tutorial in the hopes both fully understanding the underlying concepts and to properly communicate those concepts to whomever is reading this. The goal of these tutorials is not necessarily to teach anyone M68K assembly, but rather, to learn about the Sega Genesis hardware within the context of assembly. 14 | 15 | ## Getting Ready 16 | The instructions below will help you setup and ASMX and MESS which are required to follow the tutorials. The instructions assume you are using Linux Ubuntu 14.04, I'm sure there's a ton of info available online if you're trying to install these tools on Windows. 17 | 18 | ### Build ASMX 19 | ASMX is a wonderfully simple assemler which supports both the Motorola 68000 and Zilog Z80, both processors found in the Sega Genesis. It is a no brainer, in my opinion, to use this assembler to learn how to program for the Sega Genesis. Here's how I built and installed ASMX on Ubuntu 14.04. 20 | 21 | - Download source code from here (2.0b5): http://xi6.com/projects/asmx/ 22 | - Open scr/MakeFile in a text editor and comment out the line "TARGET_ARCH = -arch ppc -arch i686" 23 | - Make, and install the binary to /usr/local/bin 24 | 25 | ### Install MESS 26 | MESS has great debugging features, install MESS (Ubuntu 14.04): 27 | 28 | - sudo apt-get mess 29 | - cd to ~/.mess 30 | - create a mess.ini configuration file by running mess -cc 31 | - edit the resulting mess.ini to your liking 32 | - launch test roms: mess genesis -cart %pathtorom% -debug 33 | -------------------------------------------------------------------------------- /filetypes.68k.conf: -------------------------------------------------------------------------------- 1 | # For complete documentation of this file, please see Geany's main documentation 2 | 3 | [styling] 4 | # Edit these in the colorscheme .conf file instead 5 | default=default 6 | comment_single=#40C040 7 | comment=#40C040 8 | commentblock=#40C040 9 | commentdirective=#40C040 10 | number=#FFE020 11 | string=#F03030 12 | operator=#C0C0C0 13 | identifier=#FF9020 14 | cpuinstruction=#00C0D0;;true 15 | mathinstruction=keyword_2 16 | register=#5080C0;;true 17 | directive=#D764C0;;true;true 18 | directiveoperand=keyword_3 19 | character=#F03030 20 | stringeol=string_eol 21 | extinstruction=keyword_4 22 | keywords2=#FF0F00 23 | 24 | [keywords] 25 | # all items must be in one line 26 | instructions=abcd abcd.b add.b add.w add.l adda.w adda.l addi.b addi.w addi.l addq.b addq.w addq.l addx.b addx.w addx.l and.b and.w and.l andi.b andi.w andi.l asl.b asl.w asl.l asr.b asr.w asr.l bcc bcc.s bcc.w bcs bcs.s bcs.w beq beq.s beq.w bge bge.s bge.w bgt bgt.s bgt.w bhi bhi.s bhi.w ble ble.s ble.w bls bls.s bls.w blt blt.s blt.w bmi bmi.s bmi.w bne bne.s bne.w bpl bpl.s bpl.w bvc bvc.s bvc.w bvs bvs.s bvs.w bchg bchg.b bchg.l bclr bclr.b bclr.l bra.s bra.w bset bset.b btst.l bsr bsr.s bsr.w btst btst.b btst.l chk chk.w clr.b clr.w clr.l cmp.b cmp.w cmp.l cmpa.w cmpa.l cmpi.b cmpi.w cmpi.l cmpm.b cmpm.w cmpm.l dbcc dbcc.w dbcs dbcs.w dbeq dbeq.s dbf dbf.w dbge dbge.w dbgt dbgt.w dbhi dbhi.w dble dble.w dbls dbls.w dblt dblt.w dbmi dbmi.w dbne dbne.w dbpl dbpl.w dbt dbt.w dbvc dbvc.w dbvs dbvs.w dbra dbra.w divs divs.w divu divu.w eor.b eor.w eor.l eori.b eori.w eori.l exg exg.l ext.w ext.l illegal jmp jsr lea lea.l link lsl.b lsl.w lsl.l lsr.b lsr.w lsr.l move.b move.w move.l movea.w movea.l movem.w movem.l movep.w movep.l moveq moveq.l muls muls.w mulu mulu.w nbcd nbcd.b neg.b neg.w neg.l negx.b negx.w negx.l nop not.b not.w not.l or.b or.w or.l ori.b ori.w ori.l pea pea.l reset rol.b rol.w rol.l ror.b ror.w ror.l roxl.b roxl.w roxl.l roxr.b roxr.w roxr.l rte rtr rts sbcd sbcd.b scc scc.b scs scs.b seq seq.b sf sf.b sge sge.b sgt sgt.b shi shi.b sle sle.b sls sls.b slt slt.b smi smi.b sne sne.b spl spl.b st st.b svc svc.b svs svs.b stop sub.b sub.w sub.l suba.w suba.l subi.b subi.w subi.l subq.b subq.w subq.l subx.b subx.w subx.l swap swap.w tas tas.b trap trapv tst.b tst.w tst.l unlk jbsr jra jhi jls jcc jne jeq jvc jvs jpl jmi jge jlt jgt jle 27 | registers=a0 a0.w a0.l a1 a1.w a1.l a2 a2.w a2.l a3 a3.w a3.l a4 a4.w a4.l a5 a5.w a5.l a6 a6.w a6.l a7 a7.w a7.l d0 d0.w d0.l d1 d1.w d1.l d2 d2.w d2.l d3 d3.w d3.l d4 d4.w d4.l d5 d5.w d5.l d6 d6.w d6.l d7 d7.w d7.l sr ccr pc usp ssp sp fp 28 | directives=org list include incbin equ macro endm align dc.b dc.w dc.l 29 | 30 | [lexer_properties] 31 | #http://www.scintilla.org/SciTEDoc.html 32 | fold.asm.comment.explicit=1 33 | #keywords2.68k=HBlankInterrupt: 34 | 35 | [settings] 36 | # default extension used when saving files 37 | extension=68k 38 | lexer_filetype=ASM 39 | tag_parser=ASM 40 | 41 | # the following characters are these which a "word" can contains, see documentation 42 | wordchars=_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 43 | 44 | # single comments, like # in this file 45 | comment_single=; 46 | # multiline comments 47 | #comment_open= 48 | #comment_close= 49 | 50 | # set to false if a comment character/string should start at column 0 of a line, true uses any 51 | # indentation of the line, e.g. setting to true causes the following on pressing CTRL+d 52 | #command_example(); 53 | # setting to false would generate this 54 | # command_example(); 55 | # This setting works only for single line comments 56 | comment_use_indent=true 57 | 58 | # context action command (please see Geany's main documentation for details) 59 | context_action_cmd= 60 | 61 | [indentation] 62 | #width=4 63 | # 0 is spaces, 1 is tabs, 2 is tab & spaces 64 | #type=0 65 | 66 | [build_settings] 67 | # %f will be replaced by the complete filename 68 | # %e will be replaced by the filename without extension 69 | # (use only one of it at one time) 70 | compiler=asmx -C 68000 -e -w -b 0 -l out/rom.lst -o out/rom.bin -- "%f" 71 | #compiler=asmx "%f" 72 | 73 | [build-menu] 74 | FT_00_LB=Build Genesis ROM 75 | FT_00_CM=./build.sh 76 | FT_00_WD=%p 77 | FT_01_LB=Build & Debug 78 | FT_01_CM=./build.sh -d 79 | FT_01_WD=%p 80 | -------------------------------------------------------------------------------- /z80.lang: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | text/x-z80 6 | 7 | *.z80 8 | ; 9 | 10 | 11 | 12 |