Skip to content

Commit

Permalink
WIP more wip
Browse files Browse the repository at this point in the history
  • Loading branch information
smoynes committed Dec 13, 2023
1 parent b0a1148 commit 7207d57
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 73 deletions.
152 changes: 81 additions & 71 deletions internal/monitor/traps.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,107 +194,117 @@ var TrapPuts = Routine{
},
}

// TrapGetc is the system call to prompt the user and wait for a character of
// input.
// TrapGetc is the system call to prompt the user and wait for a character of input.
//
// - Table: 0x0000
// - Vector: 0x20
// - Handler: 0x04a0
//
// Adapted from Fig. 9.12, 3/e.
// Adapted from Fig. 9.15, 3/e. TODO: This does not disable interrupts.
var TrapGetc = Routine{
Name: "GETC",
Vector: vm.TrapTable + vm.Word(vm.TrapGETC),
Orig: 0x04a0,
Symbols: asm.SymbolTable{
"START": 0x04a0,
"L1": 0x04a4,
"LOOP": 0x04a8,
"L2": 0x04aa,
"INPUT": 0x04af,
"L3": 0x04b2,
"L4": 0x04b5,

"SAVER1": 0x04bc,
"SAVER2": 0x04bd,
"SAVER3": 0x04be,
"NEWLINE": 0x04bf,
"DSR": 0x04c0,
"DDR": 0x04c1,
"KBSR": 0x04c2,
"KBDR": 0x04c3,
"PROMPT": 0x04c4,
"START": 0x04a0,
"LOOP": 0x04a8,
"INPUT": 0x04af,
"NEWLINE": 0x04ad,
"PROMPT": 0x04ae,
"WRITECHAR": 0x04af,
"READCHAR": 0x04b3,
"SAVEREG": 0x04b7,
"RESTOREREG": 0x04be,

"SAVER1": 0x04c5,
"SAVER2": 0x04c6,
"SAVER3": 0x04c7,
"SAVER4": 0x04c8,
"SAVER5": 0x04c9,
"SAVER6": 0x04ca,

"DSR": 0x04cb,
"DDR": 0x04cc,
"KBSR": 0x04cd,
"KBDR": 0x04ce,
},
Code: []asm.Operation{
// Store registers to restore before return.
&asm.ST{SR: "R1", SYMBOL: "SAVER1"},
&asm.ST{SR: "R2", SYMBOL: "SAVER2"},
&asm.ST{SR: "R3", SYMBOL: "SAVER3"},
&asm.LD{DR: "R2", SYMBOL: "NEWLINE"},

/*L1:0x04a4*/
&asm.LDI{DR: "R1", SYMBOL: "DSR"}, // Check if DDR is empty.
&asm.BR{NZP: asm.CondZP, SYMBOL: "L1"},
&asm.STI{SR: "R2", SYMBOL: "DDR"}, // Echo newline.

// Load prompt address
&asm.JSR{SYMBOL: "SAVEREG"},
&asm.LEA{DR: "R1", SYMBOL: "PROMPT"},

/*LOOP:0x04a8*/
&asm.LDR{DR: "R0", SR: "R1", OFFSET: 0},
&asm.BR{NZP: asm.CondZP, SYMBOL: "INPUT"},
/*L2:0x04aa*/
&asm.LDI{DR: "R3", SYMBOL: "DSR"}, // Check again if DDR is ready.
&asm.BR{NZP: asm.CondZP, SYMBOL: "L2"},
&asm.STI{SR: "R0", SYMBOL: "DDR"}, // Echo next prompt char.

/*LOOP:0x04a2*/
&asm.LDR{DR: "R2", SR: "R1", OFFSET: 0}, // Get next prompt character.
&asm.JSR{SYMBOL: "WRITECHAR"}, // Echo prompt character.
&asm.ADD{DR: "R1", SR1: "R1", LITERAL: 1}, // Increment prompt pointer.
&asm.BR{NZP: asm.CondNZP, SYMBOL: "LOOP"}, // Iterate to LOOP.

/*INPUT:0x04af*/
&asm.LDI{DR: "R3", SYMBOL: "KBSR"}, // Check for KBD ready.
&asm.BR{NZP: asm.CondZP, SYMBOL: "INPUT"},
&asm.LDI{DR: "R0", SYMBOL: "KBDR"}, // Load KBD input into trap param.

/*L3:0x04b2*/
&asm.LDI{DR: "R3", SYMBOL: "DSR"}, // Check yet again if DDR ready.
&asm.BR{NZP: asm.CondZP, SYMBOL: "L3"},
&asm.STI{SR: "R0", SYMBOL: "DDR"}, // Echo input.
/*INPUT:0x04a6*/
&asm.JSR{SYMBOL: "READCHAR"}, // Get character input.
&asm.ADD{DR: "R2", SR1: "R0", LITERAL: 0}, // Move char for echo.
&asm.JSR{SYMBOL: "WRITECHAR"}, // Echo to monitor.

/*L4:0x04b5*/
&asm.LDI{DR: "R3", SYMBOL: "DSR"}, // Check once moce if DDR is ready.
&asm.BR{NZP: asm.CondZP, SYMBOL: "L4"},
&asm.STI{SR: "R2", SYMBOL: "DDR"}, // Echo newline.
&asm.LD{DR: "R2", SYMBOL: "NEWLINE"},
&asm.JSR{SYMBOL: "WRITECHAR"}, // Echo newline.
&asm.JSR{SYMBOL: "RESTOREREG"}, // Restore registers.
&asm.RTI{}, // Terminate trap routine.

// Restore work registers.
&asm.LD{DR: "R1", SYMBOL: "SAVER1"},
&asm.LD{DR: "R2", SYMBOL: "SAVER2"},
&asm.LD{DR: "R3", SYMBOL: "SAVER3"},
/*NEWLINE:0x04ad*/
&asm.FILL{LITERAL: 0x000a},
/*PROMPT:0x04ae*/
&asm.STRINGZ{LITERAL: "\nInput a character> "},

/*WRITECHAR:0x04af*/
&asm.LDI{DR: "R3", SYMBOL: "DSR"},
&asm.BR{NZP: asm.CondZP, SYMBOL: "WRITECHAR"},
&asm.STI{SR: "R2", SYMBOL: "DDR"},
&asm.RET{},

/*READCHAR:0x04b3*/
&asm.LDI{DR: "R3", SYMBOL: "KBSR"},
&asm.BR{NZP: asm.CondZP, SYMBOL: "READCHAR"},
&asm.LDI{DR: "R0", SYMBOL: "KBDR"},
&asm.RET{},

/*SAVEREG:0x04b7*/
&asm.ST{SR: "R1", SYMBOL: "SAVER1"},
&asm.ST{SR: "R2", SYMBOL: "SAVER2"},
&asm.ST{SR: "R3", SYMBOL: "SAVER3"},
&asm.ST{SR: "R4", SYMBOL: "SAVER4"},
&asm.ST{SR: "R5", SYMBOL: "SAVER5"},
&asm.ST{SR: "R6", SYMBOL: "SAVER6"},
&asm.RET{},

// Return from trap.
&asm.RTI{},
/*RESTOREREG:0x04be*/
&asm.ST{SR: "R1", SYMBOL: "SAVER1"},
&asm.ST{SR: "R2", SYMBOL: "SAVER2"},
&asm.ST{SR: "R3", SYMBOL: "SAVER3"},
&asm.ST{SR: "R4", SYMBOL: "SAVER4"},
&asm.ST{SR: "R5", SYMBOL: "SAVER5"},
&asm.ST{SR: "R6", SYMBOL: "SAVER6"},
&asm.RET{},

// Stored register allocations.
/*SAVER1:0x04bc*/
/*SAVER1:0x04c5*/
&asm.BLKW{ALLOC: 0x0001},
/*SAVER2:0x04bd*/
/*SAVER2:0x04c6*/
&asm.BLKW{ALLOC: 0x0001},
/*SAVER3:0x04be*/
/*SAVER3:0x04c7*/
&asm.BLKW{ALLOC: 0x0001},
/*SAVER4:0x04c8*/
&asm.BLKW{ALLOC: 0x0001},
/*SAVER5:0x04c9*/
&asm.BLKW{ALLOC: 0x0001},
/*SAVER6:0x04ca*/
&asm.BLKW{ALLOC: 0x0001},

// Address constants.
/*DSR:0x04bf*/
/*DSR:0x04cb*/
&asm.FILL{LITERAL: 0xfe02},
/*DDR:0x04c0*/
/*DDR:0x04cc*/
&asm.FILL{LITERAL: 0xfe04},
/*KBSR:0x04c1*/
/*KBSR:0x04cd*/
&asm.FILL{LITERAL: 0xfe00},
/*DDR:0x04c2*/
/*DDR:0x04ce*/
&asm.FILL{LITERAL: 0xfe02},
/*NEWLINE:0x04c3*/
&asm.FILL{LITERAL: 0x000a},

/*PROMPT:0x04c4*/
&asm.STRINGZ{LITERAL: "Input a character>"},
},
}
4 changes: 2 additions & 2 deletions internal/monitor/traps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestTrap_Getc(tt *testing.T) {

unsafeLoad(loader, code)

ctx, cancel := context.WithTimeout(context.TODO(), 500 * time.Millisecond)
ctx, cancel := context.WithTimeout(context.TODO(), 500*time.Millisecond)

go func() {
for {
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestTrap_Halt(tt *testing.T) {
}

image := SystemImage{
logger: t.Logger(),
logger: t.Logger(),
Symbols: nil,
Traps: []Routine{
TrapHalt,
Expand Down

0 comments on commit 7207d57

Please sign in to comment.