Serial port debug output

This commit is contained in:
Jeremy Penner 2019-01-29 19:35:48 -05:00
parent eeb1e86cba
commit 56fac17626
6 changed files with 90 additions and 19 deletions

BIN
game.exe

Binary file not shown.

BIN
game.prj

Binary file not shown.

32
serial.c Executable file
View file

@ -0,0 +1,32 @@
#include <dos.h>
#include "serial.h"
int comport = 0;
#define SER_LATCH_LO 0
#define SER_LATCH_HI 1
#define SER_TX 0
#define SER_LCR 3
#define SER_LSR 5
void ser_init(int port, int baudrate, int protocol) {
int far *comport_addr = MK_FP(0x0040, 0x0000);
int lcr;
comport = comport_addr[port];
outp(comport + SER_LCR, 0x80);
outp(comport + SER_LATCH_HI, baudrate >> 8);
outp(comport + SER_LATCH_LO, baudrate & 0xff);
outp(comport + SER_LCR, protocol);
}
void ser_write_byte(char byte) {
while (!(inp(comport + SER_LSR) & 0x20)) {}
outp(comport + SER_TX, byte);
}
void ser_write(char *str) {
for (; *str; str ++) {
ser_write_byte(*str);
}
}

24
serial.h Executable file
View file

@ -0,0 +1,24 @@
#define SER_COM1 0
#define SER_COM2 1
#define SER_COM3 2
#define SER_COM4 3
#define SER_8N1 0x03
#define BAUD_50 0x0900
#define BAUD_110 0x0417
#define BAUD_220 0x020c
#define BAUD_300 0x0180
#define BAUD_600 0x00c0
#define BAUD_1200 0x0060
#define BAUD_2400 0x0030
#define BAUD_4800 0x0018
#define BAUD_9600 0x000c
#define BAUD_19200 0x0006
#define BAUD_38400 0x0003
#define BAUD_57600 0x0002
#define BAUD_115200 0x0001
void ser_init(int port, int baudrate, int protocol);
void ser_write_byte(char byte);
void ser_write(char *str);

View file

@ -7,6 +7,7 @@
#include "mouse.h" #include "mouse.h"
#include "tiff.h" #include "tiff.h"
#include "tiles.h" #include "tiles.h"
#include "serial.h"
/*** S C R A T C H ***/ /*** S C R A T C H ***/
@ -117,32 +118,46 @@ void game_init() {
scroll(0, 0); scroll(0, 0);
} }
void showDialog() {
game.state = STATE_DIALOG;
game.footer.dy = 1;
}
void dialogThink() {
if (keyWasPressed(K_SPACE)) {
game.footer.dy = -1;
}
game.footer.y += game.footer.dy;
if (game.footer.dy > 0 && game.footer.y > 24) {
game.footer.y = 24;
game.footer.dy = 0;
} else if (game.footer.dy < 0 && game.footer.y < 0) {
game.footer.y = 0;
game.footer.dy = 0;
game.state = STATE_MAP;
}
setSplitScreen(399 - (game.footer.y << 1));
}
void overworldThink() {
if (keyWasPressed(K_SPACE)) {
showDialog();
}
playerThink(&game.player);
scroll(game.player.x - 152, game.player.y - 92);
}
int main() { int main() {
game_init(); game_init();
ser_init(SER_COM2, BAUD_19200, SER_8N1);
ser_write("JORTS QUEST DEBUG OUTPUT\r\n");
while (!keyIsDown(K_ESC)) { while (!keyIsDown(K_ESC)) {
kbd_debounce(); kbd_debounce();
if (game.state == STATE_MAP) { if (game.state == STATE_MAP) {
if (keyWasPressed(K_SPACE)) { overworldThink();
game.state = STATE_DIALOG;
game.footer.dy = 1;
}
playerThink(&game.player);
scroll(game.player.x - 152, game.player.y - 92);
} else if (game.state == STATE_DIALOG) { } else if (game.state == STATE_DIALOG) {
if (keyWasPressed(K_SPACE)) { dialogThink();
game.footer.dy = -1;
}
game.footer.y += game.footer.dy;
if (game.footer.dy > 0 && game.footer.y > 24) {
game.footer.y = 24;
game.footer.dy = 0;
} else if (game.footer.dy < 0 && game.footer.y < 0) {
game.footer.y = 0;
game.footer.dy = 0;
game.state = STATE_MAP;
}
setSplitScreen(399 - (game.footer.y << 1));
} }
drawEntity(&game.player); drawEntity(&game.player);
drawScreen(); drawScreen();

Binary file not shown.