Skip to content

Commit

Permalink
Fix #143 (Frame Buffer: *HELP MOS loops forever)
Browse files Browse the repository at this point in the history
Change-Id: If51b0a7f5a515e574f3f4e972652988c36a0d8ae
  • Loading branch information
hoglet67 committed Dec 7, 2021
1 parent fc1bfd0 commit fe913a2
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 36 deletions.
28 changes: 17 additions & 11 deletions src/programs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2803,18 +2803,22 @@ static const unsigned char dormann_d65c02[] = {

#endif

// Careful, this is currently 252 bytes (4 spare!)
// Careful, this now starts at &2C0

static const unsigned char osword_driver[] = {
0xa9, 0x20, 0x20, 0xee, 0xff, 0xa9, 0x09, 0x85, 0x81, 0xa0, 0x0a, 0x84,
0x80, 0xb9, 0x5d, 0x03, 0x5a, 0x20, 0x4f, 0x03, 0x7a, 0x88, 0x10, 0xf3,
0xc8, 0xa9, 0x04, 0xa2, 0x01, 0x20, 0xf4, 0xff, 0xa9, 0x68, 0x8d, 0x0e,
0x02, 0xa9, 0x03, 0x8d, 0x0f, 0x02, 0xad, 0x0c, 0x02, 0x8d, 0x71, 0x03,
0xad, 0x0d, 0x02, 0x8d, 0x72, 0x03, 0xa9, 0x6c, 0x8d, 0x0c, 0x02, 0xa9,
0x03, 0x8d, 0x0d, 0x02, 0xa9, 0x02, 0x85, 0x81, 0xa9, 0x0e, 0x85, 0x80,
0xa9, 0x00, 0x20, 0x4f, 0x03, 0xa9, 0x09, 0x85, 0x84, 0xa9, 0x06, 0xa2,
0x80, 0xa0, 0x00, 0x20, 0xf1, 0xff, 0xe6, 0x80, 0x60, 0x48, 0xa9, 0x03,
0x8d, 0xe2, 0xfe, 0x68, 0x8d, 0xe4, 0xfe, 0x60, 0x8d, 0xf8, 0xfe, 0x60,
0x48, 0xc9, 0x0c, 0xf0, 0x1b, 0xc9, 0x0d, 0xf0, 0x17, 0xc9, 0x1e, 0xf0,
0x13, 0xc9, 0x20, 0x90, 0x14, 0xee, 0x18, 0x03, 0xad, 0x18, 0x03, 0x18,
0x6d, 0x08, 0x03, 0xcd, 0x0a, 0x03, 0x90, 0x05, 0xa9, 0x00, 0x8d, 0x18,
0x03, 0xa9, 0x03, 0x8d, 0xe2, 0xfe, 0x68, 0x8d, 0xe4, 0xfe, 0x60, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xa9, 0x09, 0x85, 0x81, 0xa0, 0x2e, 0x84, 0x80,
0xb9, 0xc0, 0x02, 0x5a, 0x20, 0x4a, 0x03, 0x7a, 0x88, 0x10, 0xf3, 0xc8,
0xa9, 0x04, 0xa2, 0x01, 0x20, 0xf4, 0xff, 0xa9, 0x58, 0x8d, 0x0e, 0x02,
0xa9, 0x03, 0x8d, 0x0f, 0x02, 0xad, 0x0c, 0x02, 0x8d, 0x61, 0x03, 0xad,
0x0d, 0x02, 0x8d, 0x62, 0x03, 0xa9, 0x5c, 0x8d, 0x0c, 0x02, 0xa9, 0x03,
0x8d, 0x0d, 0x02, 0xa9, 0x02, 0x85, 0x81, 0xa9, 0x0e, 0x85, 0x80, 0xa9,
0x00, 0x20, 0x4a, 0x03, 0xa9, 0x09, 0x85, 0x84, 0xa9, 0x06, 0xa2, 0x80,
0xa0, 0x00, 0x20, 0xf1, 0xff, 0xe6, 0x80, 0x60, 0x8d, 0xf8, 0xfe, 0x60,
0xc9, 0x00, 0xf0, 0x03, 0x4c, 0xea, 0xea, 0x86, 0xf0, 0x84, 0xf1, 0xa0,
0x04, 0xb1, 0xf0, 0x99, 0xb1, 0x02, 0x88, 0xc0, 0x02, 0xb0, 0xf6, 0xb1,
0xf0, 0x85, 0xe9, 0x88, 0xb1, 0xf0, 0x85, 0xe8, 0x90, 0x07, 0xa9, 0x07,
Expand All @@ -2829,8 +2833,10 @@ static const unsigned char osword_driver[] = {
0xa0, 0xb0, 0x9d, 0x20, 0xe7, 0xff, 0xa5, 0xff, 0x2a, 0xa9, 0x00, 0x60
};

const unsigned char *host_oswrch_redirector = osword_driver;

void copy_test_programs(uint8_t *memory) {
memcpy(memory + 0x300, osword_driver, sizeof(osword_driver));
memcpy(memory + 0x2C0, osword_driver, sizeof(osword_driver));

memcpy(memory + 0x800, sphere, sizeof(sphere));

Expand Down
3 changes: 2 additions & 1 deletion src/programs.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#ifndef PROGRAMS_H
#define PROGRAMS_H

extern const unsigned char *host_oswrch_redirector;

extern void copy_test_programs(uint8_t *memory);

#endif

14 changes: 4 additions & 10 deletions src/tube-commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "gitversion.h"
#include "copro-defs.h"
#include "utils.h"
#include "programs.h"

static int doCmdHelp(const char *params);
static int doCmdTest(const char *params);
Expand Down Expand Up @@ -402,16 +403,9 @@ int doCmdPiVDU(const char *params) {
beeb_vdu(13);
beeb_vdu(32);
if (device & VDU_PI) {
// Install a host oswrch redirector (for output of OSCLI commands)
// PHA 48
// LDA #&03 A9 03
// STA &FEE2 8D E2 FE
// PLA 68
// STA &FEE4 8D E4 FE
// RTS 60
uint8_t data[] = { 0x48, 0xa9, 0x03, 0x8d, 0xe2, 0xfe, 0x68, 0x8d, 0xe4, 0xfe, 0x60} ;
for (uint16_t i = 0; i < sizeof(data); i++) {
write_host_byte(WRCHANDLER + i, data[i]);
// Install the same host oswrch redirector used by the 6502
for (uint16_t i = 0; i < 0x40; i++) {
write_host_byte(WRCHANDLER + i, host_oswrch_redirector[i]);
}
write_host_word(WRCVEC, WRCHANDLER);
}
Expand Down
62 changes: 48 additions & 14 deletions tools/frame_buffer/osword.asm
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,58 @@ osword6_addr_lo = osword6_param + 0
osword6_addr_hi = osword6_param + 1
osword6_data = osword6_param + 4

org &0300
org &02C0
guard &300

.start

.init
;; Host-side OSWRCH Redirector
;;
;; This redirects OSWRCH calls on the host back over to the Pi VDU driver
;;
;; It's used for the output of MOS command (like *CAT, *HELP, etc)

.host_oswrch_start
;; Stack the character to be printed
PHA
;; Emulate the POS VDU variable at &0318
;; This is used directly by *HELP MOS for padding and also by *CAT in ADFS
CMP #12 ; Clear screen returns cursor to POS=0
BEQ zero_pos
CMP #13 ; So does carriage return
BEQ zero_pos
CMP #30 ; So does home cursor
BEQ zero_pos
;; There are other cases we ignore for now (VDU 8; VDU 9; VDU 31,x,y; VDU 127)
;; as these are very unlikely to be emitted by the POS commands that read back POS
CMP #32 ; Set C=1 if printable char (i.e. space or greater)
BCC write_fifo
INC &0318 ; printable char, so increment POS by one
LDA &0318 ; compare POS to the window width
CLC
ADC &0308 ; plus Window Left
CMP &030A ; compare to Window Right
BCC write_fifo ; Still within window?
.zero_pos
;; Zero pos (cursor in left most columb)
LDA #&00
STA &0318
.write_fifo
;; Select the VDU FIFO at &FEE4
LDA #&03
STA &FEE2
;; Restore the character to be printed
PLA
;; Write character to the VDU FIFO
STA &FEE4
RTS
.host_oswrch_end

org &0300
clear &300,&3ff
guard &400

;; Leave cursor in col 1
LDA #32
JSR oswrch
.init

;; Copy minimal OSWRCH to host at 0900
LDA #page
Expand Down Expand Up @@ -87,15 +130,6 @@ org &0300
INC osword6_addr_lo
RTS

.host_oswrch_start
PHA
LDA #&03
STA &FEE2
PLA
STA &FEE4
RTS
.host_oswrch_end

.parasite_oswrch
STA &FEF8
RTS
Expand Down

0 comments on commit fe913a2

Please sign in to comment.