1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-12-26 05:08:06 +11:00

emul/8086: implement AT-XY

This commit is contained in:
Virgil Dupras 2020-10-24 23:00:45 -04:00
parent d11ac3f006
commit de9103942d
4 changed files with 58 additions and 5 deletions

View File

@ -55,6 +55,9 @@
#define signext32(value) (int32_t)(int16_t)(value)
#define getsegreg(regid) segregs[regid]
#define putsegreg(regid, writeval) segregs[regid] = writeval
// Warning: those macros below *can't* be called with reg*l and reg*h
#define getreg8(regid) regs.byteregs[byteregtable[regid]]
#define putreg8(regid, writeval) regs.byteregs[byteregtable[regid]] = writeval
#define makeflagsword() \
( \

View File

@ -38,9 +38,7 @@
#define putmem8(x, y, z) write86(segbase(x) + y, z)
#define putmem16(x, y, z) writew86(segbase(x) + y, z)
#define getreg16(regid) regs.wordregs[regid]
#define getreg8(regid) regs.byteregs[byteregtable[regid]]
#define putreg16(regid, writeval) regs.wordregs[regid] = writeval
#define putreg8(regid, writeval) regs.byteregs[byteregtable[regid]] = writeval
typedef void (*INTHOOK) ();
union _bytewordregs_ {

View File

@ -1,7 +1,11 @@
#include <stdint.h>
#include <stdio.h>
#include <curses.h>
#include "cpu.h"
#define WCOLS 80
#define WLINES 25
#ifndef FBIN_PATH
#error FBIN_PATH needed
#endif
@ -10,23 +14,43 @@ extern uint8_t byteregtable[8];
extern union _bytewordregs_ regs;
extern INTHOOK INTHOOKS[0x100];
static FILE *fp;
static int retcode = 0;
WINDOW *bw, *dw, *w;
/* we have a fake INT API:
INT 1: EMIT. AL = char to spit
INT 2: KEY. AL = char read
INT 3: AT-XY. AL = x, BL = y
*/
void int1() {
putchar(getreg8(regal));
uint8_t val = regs.byteregs[regal];
if (fp != NULL) {
putchar(val);
} else {
if (val >= 0x20 || val == '\n') {
wechochar(w, val);
} else if (val == 0x08) {
int y, x; getyx(w, y, x);
wmove(w, y, x-1);
}
}
}
void int2() {
putreg8(regal, getchar());
regs.byteregs[regal] = getchar();
}
void int3() {
wmove(w, regs.byteregs[regbl], regs.byteregs[regal]);
}
int main(int argc, char *argv[])
{
INTHOOKS[1] = int1;
INTHOOKS[2] = int2;
INTHOOKS[3] = int3;
reset86();
// initialize memory
FILE *bfp = fopen(FBIN_PATH, "r");
@ -41,6 +65,32 @@ int main(int argc, char *argv[])
c = getc(bfp);
}
fclose(bfp);
while (exec86(100));
w = NULL;
if (argc == 2) {
fp = fopen(argv[1], "r");
if (fp == NULL) {
fprintf(stderr, "Can't open %s\n", argv[1]);
return 1;
}
while (exec86(100));
fclose(fp);
} else if (argc == 1) {
initscr(); cbreak(); noecho(); nl(); clear();
// border window
bw = newwin(WLINES+2, WCOLS+2, 0, 0);
wborder(bw, 0, 0, 0, 0, 0, 0, 0, 0);
wrefresh(bw);
// debug panel
dw = newwin(1, 30, LINES-1, COLS-30);
w = newwin(WLINES, WCOLS, 1, 1);
scrollok(w, 1);
while (exec86(100)) {
//debug_panel();
}
nocbreak(); echo(); delwin(w); delwin(bw); delwin(dw); endwin();
printf("\nDone!\n");
//emul_printdebug();
}
return 0;
}

View File

@ -7,6 +7,8 @@ RS_ADDR 0x80 - CONSTANT SYSVARS
353 LOAD ( xcomp core low )
CODE (emit) AX POPx, 1 INT, ;CODE
CODE (key) 2 INT, AH 0 MOVri, AX PUSHx, ;CODE
: COLS 80 ; : LINES 25 ;
CODE AT-XY ( x y ) BX POPx, AX POPx, 3 INT, ;CODE
380 LOAD ( xcomp core high )
(entry) _ ( Update LATEST ) PC ORG @ 8 + !
EOT,