lonestar

0x10c-inspired space game based on the DCPU-16
git clone git://squid-tech.com/lonestar.git
Log | Files | Refs | README

commit 636233327aa75d0d8b27f49f1641691615bac534
parent 491c14f30a1a9ef953aeeb1a7a63205732f132c0
Author: Josh Moore <jxm5210@rit.edu>
Date:   Wed, 20 Nov 2019 22:51:27 -0500

Add beginnings of the J-TEK Standard Kernel

Diffstat:
Abin/JSK.dasm | 285+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mbin/rom.bin | 0
Dbin/rom.dasm | 40----------------------------------------
Msrc/LoneStar/Assets/Scripts/DCPU16Controller.cs | 2+-
4 files changed, 286 insertions(+), 41 deletions(-)

diff --git a/bin/JSK.dasm b/bin/JSK.dasm @@ -0,0 +1,284 @@ +; +; J-TEK STANDARD KERNEL +; (c) J-TEK 1986 +; +; This module contains utilities for basic I/O, as well as up-to-date +; drivers for supported hardware devices. +; +; Registers A, B, C, I, J should be considered temporary registers, and are not +; guaranteed to be preserved between through subroutine calls. +; Registers X, Y, Z are guaranteed to be preserved through subroutine calls. +; + +; The main kernel routine to be run when the DCPU-16 is powered on. +kernelmain: + SET A, welcomestr + JSR printstr + + ;\TODO Poll and initialize devices + + JSR newline + + SET A, welcomestr2 + JSR printstr + + JSR newline + JSR newline + + SET A, 62 ; '>' + JSR printchar + + SET A, 32 + testloop: + JSR printchar + ADD A, 1 + IFL A, 127 + SET PC, testloop + +stop: + SET PC, stop + + + +; ==== CONSOLE UTILITIES ==== +; This section contains routines to facilitate displaying console characters. + +; global console cursor position +CONSOLE_ROW: DAT 0x0000 +CONSOLE_COL: DAT 0x0000 + +welcomestr: DAT "J-TEK STANDARD KERNEL\n\0" +welcomestr2: DAT "Initialization complete.\0" + +; Print a null-terminated string. +; A = The address of the string in memory. +printstr: + IFE [A], 0 + SET PC, POP + + SET PUSH, A + SET A, [A] + JSR printchar + SET A, POP + ADD A, 1 + SET PC, printstr + + + +; Print the ASCII character in A to the console +; +; A = ASCII character to print +; Register A will be preserved through this subroutine. +printchar: + ; check for newline + IFE A, 10 + SET PC, printchar_newline + + ; don't print unprintable ASCII + IFL A, 32 + SET PC, POP + + SET PUSH, A + SET PUSH, X + + SET B, [CONSOLE_ROW] + SET C, [CONSOLE_COL] + + ; set A to the character's font location + SUB A, 32 + MUL A, 2 ; each font character is 2 words + ADD A, jtek_standard_font + + ; set B to the initial drawing address in VRAM + MUL B, 160 + SET X, C + DIV X, 4 + ADD B, X + ADD B, 0x8000 + + ; set C to the offset within the VRAM memory cell + MOD C, 4 + SET X, 3 + SUB X, C + SET C, X + + ; draw the char + JSR char_draw + + ; increment the console cursor + JSR inc_cursor + + ; return + SET X, POP + SET A, POP + SET PC, POP + + printchar_newline: + JSR newline + SET PC, POP + + + +; draw a single 4x8 character on the screen +; +; A = starting address of character bitmap (2 words) +; B = starting memory address in display +; C = index in memory cell (0 - 3, from right) +char_draw: + SET PUSH, X + SET PUSH, Y + + SET Y, C + MUL Y, 4 ; store the cell offset for later computation + + SET X, 0x000F + MUL C, 4 + SHL X, C + SET C, 0xFFFF + SUB C, X + + SET I, 0 + char_draw_loop: + AND [B], C ; clear space for character pixels + + SET X, [A] + SET J, I + MOD J, 16 + SHR X, J + AND X, 0x000F + SHL X, Y ; isolate the row-pixels + + BOR [B], X ; OR the row-pixels into video memory + + ADD B, 20 + ADD I, 4 + IFE I, 16 + ADD A, 1 + IFL I, 32 + SET PC, char_draw_loop + + ; return + SET Y, POP + SET X, POP + SET PC, POP + + + +; Increment the console cursor, moving to the next line if necessary +inc_cursor: + ADD [CONSOLE_COL], 1 + SET A, 80 + IFL [CONSOLE_COL], A + SET PC, POP + + JSR newline + SET PC, POP + + +newline: + SET [CONSOLE_COL], 0 + ADD [CONSOLE_ROW], 1 + SET PC, POP + + + +; Standard 4x8 J-TEK kernel font +; The first word is the top half of the character, the second word is the +; bottom half. The right-most four bits of each word is the top of each segment +; bitmap. +jtek_standard_font: + DAT 0x0000, 0x0000 ; ' ' + DAT 0x2220, 0x2022 ; '!' + DAT 0x5500, 0x0000 ; '"' + DAT 0x7500, 0x0057 ; '#' + DAT 0x4720, 0x2717 ; '$' + DAT 0x1510, 0x4542 ; '%' + DAT 0x1000, 0x2562 ; '&' + DAT 0x2200, 0x0000 ; ''' + DAT 0x4210, 0x1244 ; '(' + DAT 0x1240, 0x4211 ; ')' + DAT 0x5250, 0x0000 ; '*' + DAT 0x2000, 0x0027 ; '+' + DAT 0x0000, 0x3100 ; ',' + DAT 0x0000, 0x0007 ; '-' + DAT 0x0000, 0x3300 ; '.' + DAT 0x1110, 0x4442 ; '/' + DAT 0x5570, 0x7555 ; '0' + DAT 0x2620, 0x7222 ; '1' + DAT 0x1170, 0x7447 ; '2' + DAT 0x1170, 0x7113 ; '3' + DAT 0x5310, 0x1117 ; '4' + DAT 0x4470, 0x7117 ; '5' + DAT 0x4470, 0x7557 ; '6' + DAT 0x1570, 0x1111 ; '7' + DAT 0x5570, 0x7557 ; '8' + DAT 0x5570, 0x1117 ; '9' + DAT 0x6600, 0x0660 ; ':' + DAT 0x6600, 0x0620 ; ';' + DAT 0x1000, 0x0012 ; '<' + DAT 0x7000, 0x0070 ; '=' + DAT 0x2000, 0x0021 ; '>' + DAT 0x5200, 0x2021 ; '?' + DAT 0x5570, 0x7571 ; '@' + DAT 0x5520, 0x5557 ; 'A' + DAT 0x5560, 0x6556 ; 'B' + DAT 0x4430, 0x3444 ; 'C' + DAT 0x5560, 0x6555 ; 'D' + DAT 0x4470, 0x7446 ; 'E' + DAT 0x4470, 0x4446 ; 'F' + DAT 0x4570, 0x7574 ; 'G' + DAT 0x5550, 0x5557 ; 'H' + DAT 0x2270, 0x7222 ; 'I' + DAT 0x2270, 0x6222 ; 'J' + DAT 0x5550, 0x5556 ; 'K' + DAT 0x4440, 0x7444 ; 'L' + DAT 0x5750, 0x5555 ; 'M' + DAT 0x5570, 0x5555 ; 'N' + DAT 0x5570, 0x7555 ; 'O' + DAT 0x5570, 0x4447 ; 'P' + DAT 0x5570, 0x1755 ; 'Q' + DAT 0x5570, 0x5556 ; 'R' + DAT 0x4470, 0x7112 ; 'S' + DAT 0x2270, 0x2222 ; 'T' + DAT 0x5550, 0x7555 ; 'U' + DAT 0x5550, 0x2555 ; 'V' + DAT 0x5550, 0x5755 ; 'W' + DAT 0x5550, 0x5552 ; 'X' + DAT 0x5550, 0x2222 ; 'Y' + DAT 0x1170, 0x7442 ; 'Z' + DAT 0x4460, 0x6444 ; '[' + DAT 0x4440, 0x1112 ; '\' + DAT 0x2260, 0x6222 ; ']' + DAT 0x5520, 0x0000 ; '^' + DAT 0x7000, 0x0000 ; '_' + DAT 0x0120, 0x0000 ; '`' + DAT 0x6000, 0x3531 ; 'a' + DAT 0x4000, 0x6556 ; 'b' + DAT 0x3000, 0x3444 ; 'c' + DAT 0x1000, 0x3553 ; 'd' + DAT 0x2000, 0x3475 ; 'e' + DAT 0x3000, 0x4464 ; 'f' + DAT 0x3000, 0x6175 ; 'g' + DAT 0x4000, 0x5564 ; 'h' + DAT 0x2000, 0x7260 ; 'i' + DAT 0x1000, 0x2510 ; 'j' + DAT 0x4000, 0x5654 ; 'k' + DAT 0x2000, 0x2222 ; 'l' + DAT 0x5000, 0x5557 ; 'm' + DAT 0x3000, 0x5555 ; 'n' + DAT 0x2000, 0x2555 ; 'o' + DAT 0x6000, 0x4465 ; 'p' + DAT 0x2000, 0x1255 ; 'q' + DAT 0x4000, 0x4457 ; 'r' + DAT 0x3000, 0x6124 ; 's' + DAT 0x2000, 0x3227 ; 't' + DAT 0x5000, 0x7555 ; 'u' + DAT 0x5000, 0x2555 ; 'v' + DAT 0x5000, 0x5755 ; 'w' + DAT 0x5000, 0x5525 ; 'x' + DAT 0x5000, 0x2225 ; 'y' + DAT 0x7000, 0x7421 ; 'z' + DAT 0x2230, 0x3224 ; '{' + DAT 0x2220, 0x2222 ; '|' + DAT 0x2260, 0x6221 ; '}' + DAT 0x5000, 0x000A ; '~'+ \ No newline at end of file diff --git a/bin/rom.bin b/bin/rom.bin Binary files differ. diff --git a/bin/rom.dasm b/bin/rom.dasm @@ -1,39 +0,0 @@ -; this program will flash all plugged-in lights - -HWN X -SET Y, 0 - -:whitestart -SET A, 1 -HWI Y - -SET A, 0x8000 -SET B, 0 ; counter -SET C, 0 ; indexer -:white -ADD C, A -SET [C], 0xFFFF -ADD B, 1 -SET C, B -IFG B, 0xFA0 -SET PC, blackstart -SET PC, white - -:blackstart -SET A, 0 -HWI Y -ADD Y, 1 -IFE Y, X -SET Y, 0 - -SET A, 0x8000 -SET B, 0 -SET C, 0 -:black -ADD C, A -SET [C], 0x0000 -ADD B, 1 -SET C, B -IFG B, 0xFA0 -SET PC, whitestart -SET PC, black- \ No newline at end of file diff --git a/src/LoneStar/Assets/Scripts/DCPU16Controller.cs b/src/LoneStar/Assets/Scripts/DCPU16Controller.cs @@ -729,7 +729,7 @@ public class DCPU16Controller : NetworkBehaviour { case 0x01: // JSR a - MEM[--REG_SP] = (ushort)(REG_PC + getInstructionSize( + MEM[REG_SP--] = (ushort)(REG_PC + getInstructionSize( (byte)((MEM[REG_PC] >> 10) & 0x3F), (byte)((MEM[REG_PC] >> 5) & 0x1F), (byte)(MEM[REG_PC] & 0x1F)