Fine tune

This commit is contained in:
Stefano Furiosi 2016-06-17 15:18:56 -07:00
parent 078c2b47f0
commit 314604d2d0
5 changed files with 234 additions and 132 deletions

View File

@ -5,28 +5,28 @@
;
;-------------------------------------------------------------------------
processor 6502
org $FF00
processor 6502
org $FF00
;-------------------------------------------------------------------------
; Memory declaration
;-------------------------------------------------------------------------
XAML .EQ $24 Last "opened" location Low
XAMH .EQ $25 Last "opened" location High
STL .EQ $26 Store address Low
STH .EQ $27 Store address High
L .EQ $28 Hex value parsing Low
H .EQ $29 Hex value parsing High
YSAV .EQ $2A Used to see if hex value is given
MODE .EQ $2B $00=XAM, $7F=STOR, $AE=BLOCK XAM
XAML equ $24 ;Last "opened" location Low
XAMH equ $25 ;Last "opened" location High
STL equ $26 ;Store address Low
STH equ $27 ;Store address High
L equ $28 ;Hex value parsing Low
H equ $29 ;Hex value parsing High
YSAV equ $2A ;Used to see if hex value is given
MODE equ $2B ;$00=XAM, $7F=STOR, $AE=BLOCK XAM
IN .EQ $0200,$027F Input buffer
IN equ $0200,$027F ;Input buffer
KBD .EQ $D010 PIA.A keyboard input
KBDCR .EQ $D011 PIA.A keyboard control register
DSP .EQ $D012 PIA.B display output register
DSPCR .EQ $D013 PIA.B display control register
KBD equ $D010 ;PIA.A keyboard input
KBDCR equ $D011 ;PIA.A keyboard control register
DSP equ $D012 ;PIA.B display output register
DSPCR equ $D013 ;PIA.B display control register
; KBD b7..b0 are inputs, b6..b0 is ASCII input, b7 is constant high
; Programmed to respond to low to high KBD strobe
@ -39,10 +39,10 @@ DSPCR .EQ $D013 PIA.B display control register
; Constants
;-------------------------------------------------------------------------
BS .EQ $DF Backspace key, arrow left key
CR .EQ $8D Carriage Return
ESC .EQ $9B ESC key
PROMPT .EQ "\" Prompt character
BS equ $DF ;Backspace key, arrow left key
CR equ $8D ;Carriage Return
ESC equ $9B ;ESC key
PROMPT equ "\\" ;Prompt character
;-------------------------------------------------------------------------
; Let's get started
@ -52,13 +52,13 @@ PROMPT .EQ "\" Prompt character
; are selected.
;-------------------------------------------------------------------------
RESET CLD Clear decimal arithmetic mode
RESET CLD ;Clear decimal arithmetic mode
CLI
LDY #%0111.1111 Mask for DSP data direction reg
STY DSP (DDR mode is assumed after reset)
LDA #%1010.0111 KBD and DSP control register mask
STA KBDCR Enable interrupts, set CA1, CB1 for
STA DSPCR positive edge sense/output mode.
LDY #%0111.1111 ;Mask for DSP data direction reg
STY DSP ; (DDR mode is assumed after reset)
LDA #%1010.0111 ;KBD and DSP control register mask
STA KBDCR ;Enable interrupts, set CA1, CB1 for
STA DSPCR ; positive edge sense/output mode.
; Program falls through to the GETLINE routine to save some program bytes
; Please note that Y still holds $7F, which will cause an automatic Escape
@ -67,36 +67,36 @@ RESET CLD Clear decimal arithmetic mode
; The GETLINE process
;-------------------------------------------------------------------------
NOTCR CMP #BS Backspace key?
BEQ BACKSPACE Yes
CMP #ESC ESC?
BEQ ESCAPE Yes
INY Advance text index
BPL NEXTCHAR Auto ESC if line longer than 127
NOTCR CMP #BS ;Backspace key?
BEQ BACKSPACE ;Yes
CMP #ESC ;ESC?
BEQ ESCAPE ;Yes
INY ;Advance text index
BPL NEXTCHAR ;Auto ESC if line longer than 127
ESCAPE LDA #PROMPT Print prompt character
JSR ECHO Output it.
ESCAPE LDA #PROMPT ;Print prompt character
JSR ECHO ;Output it.
GETLINE LDA #CR Send CR
GETLINE LDA #CR ;Send CR
JSR ECHO
LDY #0+1 Start a new input line
BACKSPACE DEY Backup text index
BMI GETLINE Oops, line's empty, reinitialize
LDY #0+1 ;Start a new input line
BACKSPACE DEY ;Backup text index
BMI GETLINE ;Oops, line's empty, reinitialize
NEXTCHAR LDA KBDCR Wait for key press
BPL NEXTCHAR No key yet!
LDA KBD Load character. B7 should be '1'
STA IN,Y Add to text buffer
JSR ECHO Display character
NEXTCHAR LDA KBDCR ;Wait for key press
BPL NEXTCHAR ;No key yet!
LDA KBD ;Load character. B7 should be '1'
STA IN,Y ;Add to text buffer
JSR ECHO ;Display character
CMP #CR
BNE NOTCR It's not CR!
BNE NOTCR ;It's not CR!
; Line received, now let's parse it
LDY #-1 Reset text index
LDA #0 Default mode is XAM
TAX X=0
LDY #-1 ;Reset text index
LDA #0 ;Default mode is XAM
TAX ;X=0
SETSTOR ASL Leaves $7B if setting STOR mode

75
README.txt Normal file
View File

@ -0,0 +1,75 @@
@@@@@@@@@@@@@@@@&^-;,;^&#@@@@@@@@@@@@@@@
@@@@@@@@@@@@#**+ ..:;^*@@@@@@@@@@@@@
@@@@@@@@@@&-:.. ... .+@@@@@@@@@@@@
@@@@@@@@%! .. ....+%@@@@@@@@@@
@@@@@@@#; . :^#@@@@@@@@
@@@@@@@= .:;;: =@@@@@@@@
@@@@@@@; ,,. .. :!+=-: :=@@@@@@@
@@@@@@*. :=?^!!--;;;^??=^, .&@@@@@@
@@@@@@+ ,??=+++=+^^++^^+^: +@@@@@@
@@@@@@? !=^;,::,-^-,..:;^! ,%@@@@@@
@@@@@@* :++!,. :++: .:;^+: ?@@@@@@@
@@@@@@%: ;?=+^!!!!-&%+--^+?&!.*@@@@@@@
@@@@@@@+ ,:,=====+^^=&**?^^=??^:+@@@@@@@
@@@@@@@#:,,.!-!!!;;!!!-^-;,;!-!.+@@@@@@@
@@@@@@@@^ :;;,..,,. ..::..,;:,%@@@@@@@
@@@@@@@@%-. ..::.::,;;!!;,,....?@@@@@@@@
@@@@@@@@@%-! ...,;;!-^^^^,. :=@@@@@@@@@
@@@@@@@@%?*=,. ..,;;,,,;;..,?@@@@@@@@@@
@@@@##%*&%#&-,.....:....:..:+?%@@@@@@@@@
@#%***%%####?;::. .......,!^**%#@@@@@@@
%%%%##%%##%##=,,:::...::,!-;^##%%%##@@@@
##%%%%%%%##%##?;,,,,;,;!-^!;+%####%%####
%%%%%%%%%####*?+!;,,,,!--!,-?###%%%%%%%%
WOZ
@@@@@@@@@@@@@@@@@@@@@@@@@^^@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@^^^^^@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@^^^^^@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@^^^^^@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@^^^^^@@@@@@@@@@@@@@@@
@@@@@@@@@@@@^^^@@@@^^@@@@^^^^@@@@@@@@@@@
@@@@@@@@^^^^^^^^^^^^^^^^^^^^^^^^^@@@@@@@
@@@@@@^^^^^^^^^^^^^^^^^^^^^^^^^^^^@@@@@@
@@@@@***************************@@@@@@@@
@@@@***************************@@@@@@@@@
@@@@**************************@@@@@@@@@@
@@@+++++++++++++++++++++++++++@@@@@@@@@@
@@@+++++++++++++++++++++++++++@@@@@@@@@@
@@@++++++++++++++++++++++++++++@@@@@@@@@
@@@@;;;;;;;;;;;;;;;;;;;;;;;;;;;;@@@@@@@@
@@@@;;;;;;;;;;;;;;;;;;;;;;;;;;;;;@@@@@@@
@@@@@;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;@@@@@
@@@@@,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,@@@@@
@@@@@@,,,,,,,,,,,,,,,,,,,,,,,,,,,,@@@@@@
@@@@@@@,,,,,,,,,,,,,,,,,,,,,,,,,,@@@@@@@
@@@@@@@@@;;;;;;;;;;;;;;;;;;;;;;;@@@@@@@@
@@@@@@@@@@;;;;;;;;@@@@;;;;;;;;@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
3.3v GND 3.3v Arduino Due
| | +------\/------+ |
| +---- 1| Vss /RES |40 -- 3k3 -+--- 52
+--- 3k3 ----- 2| RDY ϕ2 |39
| 3| ϕ1 /SO |38
+--- 3k3 ----- 4| IRQ ϕ0 |37 -------- 53
| 5| NC NC |36
+--- 3k3 ----- 6| /NMI NC |35
| 7| SYNC R/W |34 -------- 51
+------------- 8| Vcc D0 |33 -------- 49
22 --------- 9| A0 D1 |32 -------- 48
23 --------- 10| A1 D2 |31 -------- 47
24 --------- 11| A2 D3 |30 -------- 46
25 --------- 12| A3 D4 |29 -------- 45
26 --------- 13| A4 D5 |28 -------- 44
27 --------- 14| A5 D6 |27 -------- 43
28 --------- 15| A6 D7 |26 -------- 42
29 --------- 16| A7 A15 |25 -------- 30
37 --------- 17| A8 A14 |24 -------- 31
36 --------- 18| A9 A13 |23 -------- 32
35 --------- 19| A10 A12 |22 -------- 33
34 --------- 20| A11 Vss |21 ---+
+--------------+ |
GND

View File

@ -8,7 +8,7 @@ const int SERIAL_SPEED = 115200; // Arduino Serial Speed
const int CLOCK_PIN = 52; // TO 6502 CLOCK
const int RW_PIN = 53; // TO 6502 R/W
const int CLOCK_DELAY = 5; // HIGH / LOW CLOCK STATE DELAY
const int CLOCK_DELAY = 4; // HIGH / LOW CLOCK STATE DELAY
const char SERIAL_BS = 0x08;
@ -21,21 +21,21 @@ const unsigned int ROM_ADDR = 0xFF00; // ROM
const unsigned int RAM_BANK1_ADDR = 0x0000; // RAM
const unsigned int RAM_BANK2_ADDR = 0xE000; // EXTENDED RAM
const unsigned int XAML = 0x24; // Last "opened" location Low
const unsigned int XAMH = 0x25; // Last "opened" location High
const unsigned int STL = 0x26; // Store address Low
const unsigned int STH = 0x27; // Store address High
const unsigned int L = 0x28; // Hex value parsing Low
const unsigned int H = 0x29; // Hex value parsing High
const unsigned int YSAV = 0x2A; // Used to see if hex value is given
const unsigned int MODE = 0x2B; // $00=XAM, $7F=STOR, $AE=BLOCK XAM
const unsigned int XAML = 0x24; // Last "opened" location Low
const unsigned int XAMH = 0x25; // Last "opened" location High
const unsigned int STL = 0x26; // Store address Low
const unsigned int STH = 0x27; // Store address High
const unsigned int L = 0x28; // Hex value parsing Low
const unsigned int H = 0x29; // Hex value parsing High
const unsigned int YSAV = 0x2A; // Used to see if hex value is given
const unsigned int MODE = 0x2B; // $00=XAM, $7F=STOR, $AE=BLOCK XAM
const unsigned int IN = 0x200; // Input buffer ($0200,$027F)
const int RAM_BANK_1_SIZE = 4096;
const int RAM_BANK_2_SIZE = 4096;
unsigned char RAM_BANK_1[RAM_BANK_1_SIZE];
// PIA MAPPING 6821
// PIA MAPPING 6821
const unsigned int PIA_ADDR = 0xD000; // PIA 6821 ADDR BASE SPACE
const unsigned int KBD_ADDR = 0xD010; // Keyb Char - B7 High on keypress
const unsigned int KBDCR_ADDR = 0xD011; // Keyb Status - B7 High on keypress / Low when ready
@ -50,14 +50,13 @@ const unsigned char BS = 0xDF; // Backspace key, arrow left key (B7 High)
const unsigned char CR = 0x8D; // Carriage Return (B7 High)
const unsigned char ESC = 0x9B; // ESC key (B7 High)
unsigned int address; // Current address (from 6502)
unsigned int address; // Current address (from 6502)
unsigned char bus_data; // Data Bus value (from 6502)
int rw_state; // Current R/W state (from 6502)
int rw_state; // Current R/W state (from 6502)
unsigned int pre_address; // Current address (from 6502)
unsigned int pre_address; // Current address (from 6502)
unsigned char pre_bus_data; // Data Bus value (from 6502)
int pre_rw_state; // Current R/W state (from 6502)
int pre_rw_state; // Current R/W state (from 6502)
void setupAddressPins() {
@ -66,7 +65,7 @@ void setupAddressPins() {
}
}
void busMode(int mode) {
void setBusMode(int mode) {
for (int i = 0; i < NUM_DATA_PINS; ++i) {
pinMode(DATA_PINS[i], mode);
}
@ -91,15 +90,16 @@ void readData() {
}
void handleRWState() {
int curent_rw_state=digitalRead(RW_PIN);
if (rw_state != curent_rw_state) {
rw_state=curent_rw_state;
int tmp_rw_state=digitalRead(RW_PIN);
if (rw_state != tmp_rw_state) {
rw_state=tmp_rw_state;
if (rw_state) {
// State HIGH - WRITE TO 6502 Data Bus
busMode(OUTPUT);
setBusMode(OUTPUT);
} else {
// State LOW - READ FROM 6502 Data Bus
busMode(INPUT);
setBusMode(INPUT);
}
}
}
@ -111,6 +111,42 @@ void byteToDataBus(unsigned char data) {
}
}
void PIAWrite() {
switch (address) {
case KBD_ADDR:
KBD=bus_data;
break;
case KBDCR_ADDR:
KBDCR=bus_data;
break;
case DSP_ADDR:
DSP = bus_data;
switch(DSP) {
case CR:
Serial.write('\r');
Serial.write('\n');
break;
case BS:
Serial.write(SERIAL_BS);
break;
default:
Serial.write(DSP & 0x7F);
break;
}
bitClear(DSP, 7);
break;
case DSPCR_ADDR:
DSPCR=bus_data;
break;
}
}
// READ FROM DATA BUS - STORE AT RELATED ADDRESS
void readFromDataBus() {
readData();
@ -124,37 +160,40 @@ void readFromDataBus() {
RAM_BANK_2[address-RAM_BANK2_ADDR]=bus_data;
break;
case 0xD:
// 6821
switch (address) {
case KBD_ADDR:
KBD=bus_data;
break;
case KBDCR_ADDR:
KBDCR=bus_data;
break;
case DSP_ADDR:
DSP = bus_data;
if (DSP == CR) {
// Simulate CR
Serial.write('\r');
Serial.write('\n');
} else if (DSP == BS) {
// BACKSPACE
Serial.write(SERIAL_BS);
} else {
Serial.write(DSP & 0x7F);
}
// Display Ready - clear B7
bitClear(DSP, 7);
break;
case DSPCR_ADDR:
DSPCR=bus_data;
break;
}
PIAWrite();
break;
}
}
unsigned char PIARead() {
unsigned char val;
// PIA 6821
switch (address) {
case KBD_ADDR:
val=KBD;
// We'v read the char, clear B7
bitClear(KBDCR, 7);
break;
case KBDCR_ADDR:
val=KBDCR;
break;
case DSP_ADDR:
val=DSP;
break;
case DSPCR_ADDR:
val=DSPCR;
break;
default:
val=0;
}
return val;
}
// WRITE FROM DATA BUS A BYTE FROM RELATED ADDRESS
void writeToDataBus() {
unsigned char val=0;
@ -170,25 +209,7 @@ void writeToDataBus() {
val=ROM[address-ROM_ADDR];
break;
case 0xD:
// PIA 6821
switch (address) {
case KBD_ADDR:
val=KBD;
// We'v read the char, clear B7
bitClear(KBDCR, 7);
break;
case KBDCR_ADDR:
val=KBDCR;
break;
case DSP_ADDR:
val=DSP;
break;
case DSPCR_ADDR:
val=DSPCR;
break;
default:
val=0;
}
val=PIARead();
break;
default:
val=0;
@ -217,19 +238,16 @@ void handleKeyboard() {
// BS
tempKBD = 0x5F;
break;
}
KBD = tempKBD;
// Step B7 on KBD so that the code know a new char is in
bitSet(KBD, 7);
bitSet(KBDCR, 7);
}
}
void autload() {
unsigned int adddr = AUTLOAD[1] | AUTLOAD[0] << 8;
Serial.print("AUTOLOAD AT: ");
Serial.println(adddr, HEX);
@ -242,9 +260,12 @@ void autload() {
void setup() {
pinMode(CLOCK_PIN, OUTPUT);
pinMode(RW_PIN, INPUT);
setupAddressPins();
busMode(OUTPUT);
setBusMode(OUTPUT);
Serial.begin(SERIAL_SPEED);
Serial.println("----------------------------");
Serial.println("APPLE 1 REPLICA by =STID=");
Serial.println("----------------------------");
@ -257,12 +278,14 @@ void setup() {
Serial.print("ERAM: ");
Serial.print(sizeof(RAM_BANK_2));
Serial.println(" BYTE");
autload();
Serial.println("----------------------------");
}
void loop () {
void handleClock() {
// LOW CLOCK
digitalWrite(CLOCK_PIN, LOW);
delayMicroseconds(CLOCK_DELAY);
@ -273,24 +296,20 @@ void loop () {
// HIGH CLOCK
digitalWrite(CLOCK_PIN, HIGH);
delayMicroseconds(CLOCK_DELAY);
}
// ALWAYS READ ADDR
readAddress();
void handleBusRW() {
// READ OR WRITE TO BUS?
if (pre_address != address || pre_rw_state != rw_state) {
rw_state ? writeToDataBus() : readFromDataBus();
} else {
pre_address = address;
pre_rw_state = rw_state;
}
handleKeyboard();
}
// WOZ TEST (As on the Apple 1 Manual)
// 0:A9 9 AA 20 EF FF E8 8A 4C 2 0
// HELLO WORLD
// 280:A2 C BD 8B 2 20 EF FF CA D0 F7 60 8D C4 CC D2 CF D7 A0 CF CC CC C5 C8
void loop () {
handleClock();
readAddress();
handleBusRW();
handleKeyboard();
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long