Apple Seed http://www.rad51.net/blog/apple1/ blog to enjoy apple1 replica ja Jeans CMS © Weblog http://backend.userland.com/rss https://www.rad51.net/jeans/skins/jeans/images/jeans2.gif Apple Seed http://www.rad51.net/blog/apple1/ Debbuged print routine http://www.rad51.net/blog/apple1/?itemid=455
Debbuged print routine works fine.

OK. Let's go to string variable and substring routines.]]>
Basic Compiler http://www.rad51.net/blog/apple1/?itemid=455 Tue, 16 Oct 2007 15:13:22 PDT ITEM455_20071016
BASIC compiler http://www.rad51.net/blog/apple1/?itemid=446
array

Mmm...there is a bug around PRINT routine, however, putting value to array and getting value from array work well!]]>
Basic Compiler http://www.rad51.net/blog/apple1/?itemid=446 Thu, 04 Oct 2007 15:35:24 PDT ITEM446_20071004
Using stack in BASIC http://www.rad51.net/blog/apple1/?itemid=437
stack

Lines 1010 and 1060 correspond to PUSH and POP commands, respectively.]]>
BASIC http://www.rad51.net/blog/apple1/?itemid=437 Mon, 17 Sep 2007 12:32:11 PDT ITEM437_20070917
Flash writer for Replica I http://www.rad51.net/blog/apple1/?itemid=435 24LC512 as memory chip. The first version contains 4 chips, so 4 x 512K bits (total 256K bytes) can be used as strage. This writer can contain up to 32 chips, so maximum strage size is 2 M bytes. This size corresponds to aproximately 160 min for casette tape interface. I guess this is enough size for playing with Replica I. I remember, when I was using casette tape as strage for micro-computer 25 years ago, I had 3-4 tapes (47 min capacity for each).

EEPROM writer


Schematics:
Schematics

I'm now creating the firmware for this circuit.

Following photo shows that the write is connected to Replica 1.
connected]]>
Serial EEPROM http://www.rad51.net/blog/apple1/?itemid=435 Sun, 16 Sep 2007 19:16:03 PDT ITEM435_20070916
Indirect JMP http://www.rad51.net/blog/apple1/?itemid=419 There are a couple of bugs on 6502 cpu.

One of them may affect the BASIC compiler:

An indirect JMP (xxFF) will fail because the MSB will be fetched from address xx00 instead of page xx+1.

The 6502 simulater also follows this bug:

JMP bug

The BASIC compiler in my local environment now supports let statement and getting value from variables.]]>
6502 http://www.rad51.net/blog/apple1/?itemid=419 Fri, 17 Aug 2007 20:06:04 PDT ITEM419_20070817
JSR command http://www.rad51.net/blog/apple1/?itemid=405 JSR
Pushed address is 1 byte before the address that will be executed after RTS command.

For the BASIC compiler, I just completed the math (+, -, *, /, =, AND etc) and function (ABS, SGN, PEEK, and RND) routines. Next, integer variables and arrays will be supported.]]>
6502 http://www.rad51.net/blog/apple1/?itemid=405 Sun, 05 Aug 2007 23:54:52 PDT ITEM405_20070805
Div routine http://www.rad51.net/blog/apple1/?itemid=403
* = $0F40
0F40        LDA #$00        A9 00
0F42        STA $1001       8D 01 10
0F45        STA $1003       8D 03 10
0F48        LDA #$80        A9 80
0F4A        STA $1000       8D 00 10
0F4D        LDA #$0A        A9 0A
0F4F        STA $1002       8D 02 10
;Main starts here.
0F52        LDA $1003       AD 03 10
0F55        BNE OK          D0 21
0F57        LDA $1002       AD 02 10
0F5A        BEQ ERROR       F0 19
0F5C        CMP #$01        C9 01
0F5E        BNE OK          D0 18
0F60 DIVIDE BY 1
0F60        LDA $1000       AD 00 10
0F63        STA $1006       8D 06 10
0F66        LDA $1001       AD 01 10
0F69        STA $1007       8D 07 10
0F6C        LDA #$00        A9 00
0F6E        STA $1000       8D 00 10
0F71        STA $1001       8D 01 10
0F74        RTS             60
0F75 ERROR  
0F75        JMP ERROR       4C 75 0F
0F78 OK     
0F78        LDA #$00        A9 00
0F7A        STA $1004       8D 04 10
0F7D        STA $1005       8D 05 10
0F80        STA $1006       8D 06 10
0F83        STA $1007       8D 07 10
0F86        INC $1004       EE 04 10
0F89 LOOP   
0F89        CLC             18
0F8A        ROL $1004       2E 04 10
0F8D        ROL $1005       2E 05 10
0F90        CLC             18
0F91        ROL $1002       2E 02 10
0F94        ROL $1003       2E 03 10
0F97        BCC LOOP        90 F0
0F99        ROR $1003       6E 03 10
0F9C        ROR $1002       6E 02 10
0F9F        CLC             18
0FA0        ROR $1005       6E 05 10
0FA3        ROR $1004       6E 04 10
0FA6 SUB    
0FA6        SEC             38
0FA7        LDA $1000       AD 00 10
0FAA        SBC $1002       ED 02 10
0FAD        TAX             AA
0FAE        LDA $1001       AD 01 10
0FB1        SBC $1003       ED 03 10
0FB4        BCC SKIP        90 19
0FB6        STA $1001       8D 01 10
0FB9        STX $1000       8E 00 10
0FBC ADD    
0FBC        CLC             18
0FBD        LDA $1004       AD 04 10
0FC0        ADC $1006       6D 06 10
0FC3        STA $1006       8D 06 10
0FC6        LDA $1005       AD 05 10
0FC9        ADC $1007       6D 07 10
0FCC        STA $1007       8D 07 10
0FCF SKIP   
0FCF        CLC             18
0FD0        ROR $1003       6E 03 10
0FD3        ROR $1002       6E 02 10
0FD6        CLC             18
0FD7        ROR $1005       6E 05 10
0FDA        ROR $1004       6E 04 10
0FDD        BCC SUB         90 C7
0FDF END    
0FDF        RTS             60

Previous code contains bug due to mistake about carry. SBC subtracts 1 when carry is not set and doesn't when carry is set. The result is also the same: carry is set when there is no carry over.]]>
Basic Compiler http://www.rad51.net/blog/apple1/?itemid=403 Tue, 31 Jul 2007 16:01:59 PDT ITEM403_20070731
Math calc routine http://www.rad51.net/blog/apple1/?itemid=387
Add and Sub are easy:
//16bit add
    CLC
    LDA $1000
    ADC $1002
    TAX
    LDA $1001
    ADC $1003
    TAY
    RTS

//16bit sub
    CLC
    LDA $1000
    SBC $1002
    TAX
    LDA $1001
    SBC $1003
    TAY
    RTS


Mul and Dev routines are complex as follows.

First routine checks the signes of inputs. If minus, convert it to plus (Y resister remembers the number of minus input(s)):
//plus-minus-check
    LDA $1001
    AND #$80
    TAY
    BEQ ok1
    CLC
    LDA #$00
    SBC $1000
    STA $1000
    LDA #$00
    SBC $1001
    STA $1001
ok1:
    LDA $1003
    AND #$80
    BEQ ok2
    TYA
    EOR #$80
    TAY
    CLC
    LDA #$00
    SBC $1002
    STA $1002
    LDA #$00
    SBC $1003
    STA $1003
ok2:
    RTS


Mul routine is as follows:
//16bit mul
    JSR plus-minus-check
    LDA #$00
    STA $1004
    STA $1005
    LDX #$10
loop:
    ROR $1001
    ROR $1000
    BCC skip
    CLC
    LDA $1002
    ADC $1004
    STA $1004
    LDA $1003
    ADC $1005
    STA $1005
skip:
    CLC
    ROL $1002
    ROL $1003
    DEX
    BNE loop
    TYA
    BNE minus
    LDX $1004
    LDY $1005
    RTS    
minus:
    CLC
    LDA #$00
    SBC $1004
    TAX
    LDA #$00
    SBC $1005
    TAY
    RTS


Dev routine is as follows:
//16bit dev and mod
dev:
    JSR plus-minus check
    JSR main
    TYA
    BNE minus
    LDX $1006
    LDY $1007
    RTS    
minus:
    CLC
    LDA #$00
    SBC $1006
    TAX
    LDA #$00
    SBC $1007
    TAY
    RTS
mod:
    JSR plus-minus check
    JSR main
    TYA
    BNE minus2
    LDX $1000
    LDY $1001
    RTS    
minus2:
    CLC
    LDA #$00
    SBC $1000
    TAX
    LDA #$00
    SBC $1001
    TAY
    RTS
main:
    LDA $1003
    BNE ok
    LDA $1002
    BEQ error
    CMP #$01
    BNE ok
divide_by_1:
    LDA $1000
    STA $1006
    LDA $1001
    STA $1007
    LDA #$00
    STA $1000
    sta $1001
    RTS
error:
    RTS
ok:
    LDA #$00
    STA $1004
    STA $1005
    STA $1006
    STA $1007
    INC $1004
loop:
    CLC
    ROL $1004
    ROL $1005
    CLC
    ROL $1002
    ROL $1003
    BCC loop
    ROR $1003
    ROR $1002
    CLC
    ROR $1005
    ROR $1004
sub:
    CLC
    LDA $1000
    SBC $1002
    TAX
    LDA $1001
    SBC $1003
    BCS skip
    STA $1001
    STX $1000
add:
    CLC
    LDA $1004
    ADC $1006
    STA $1006
    LDA $1005
    ADC $1007
    STA $1007
skip:
    CLC
    ROR $1003
    ROR $1002
    CLC
    ROR $1005
    ROR $1004
    BCS sub
    RTS
]]>
Basic Compiler http://www.rad51.net/blog/apple1/?itemid=387 Tue, 10 Jul 2007 17:46:54 PDT ITEM387_20070710
Integer and string http://www.rad51.net/blog/apple1/?itemid=383
53(35h) +
54(36h) -

176(B0h) XX XX (2byte integer, -32768 to 32767)
   |
185(B9h) XX XX (2byte integer, -32768 to 32767)

38h: ( .......... 72h: )

193(C1h): A
  |
218(DAh): Z

C1h B0h - C1h B9h: A0 - A9
  |
DAh B0h _ DAh B9h: Z0-Z9

C1h 34h .... 72h : A( ..... ) ; array

46 63: PEEK( ..... 72h:)
47 63: RND( ..... 72h:)
48 63: SGN( ..... 72h:)
49 63: ABS( ..... 72h:)
and
18 +
19 -
20 *
21 /
22 =
23 #
24 >=
25 >
26 <=
27 <>
28 <
29 AND
30 OR
31 MOD


String may contain:

40:" ..... 41:"

C1h 40h: A$
  |
DAh 40h: Z$

C1h 40h 2A: A$( ........ 72h: )
  |
DAh 40h 2A: Z$( ........ 72h: )

C1h 40h 2A: A$( .... 23h: , .... 72h: )
  |
DAh 40h 2A: Z$( ... 23h: , ..... 72h: )


]]>
Basic Compiler http://www.rad51.net/blog/apple1/?itemid=383 Wed, 04 Jul 2007 23:03:04 PDT ITEM383_20070704
Statements http://www.rad51.net/blog/apple1/?itemid=381
1 end of line
3 : (next statement)
77 CALL
78, 79 DIM
80 TAB
81 END
82-84 INPUT
85 FOR
89 NEXT
91 RETURN
92 GOSUB
93 REM
94 LET (see below)
95 GOTO
96 IF
97-99 PRINT
100 POKE

LET statement:

"LET" can be omitted. Instead, the statement can be started from following codes:
193: A
  |
218: Z

Following codes can be added if used as integer
176: 0
  |
185: 9

When using as string,
64: $
must follow 193-218.

To change the value in an array,
45: (
must follow 193-218 or 176-185. At the end, use:
114: )


To append string,
66: (
must follow 64. At the end, use:
114: )


Finally,
113: = (for integer) or
112: = (for string)
follows. Right side is an expression of integer of string.

DIM statement
DIM A(10) etc
79 + (integer variable expression) + 52 + (integer expression) + 114 [ + ( (68) + (integer string expression) + 52 + (integer expression) + 114 | (67) + (string expression) + 34 + (integer expression) + 114) ....]

DIM A$(10) etc
78 + (string variable expression) + 34 + (integer expression ) + 114 [ + ( (68) + (integer string expression) + 52 + (integer expression) + 114 | (67) + (string expression) + 34 + (integer expression) + 114) ....]

INPUT statement
INPUT A etc
84 + (integer variable expression) [ + 38 + (integer or string variable expression) ....]

INPUT A$ etc
82 + (string variable expression) [ + 39 + (integer or string variable expression) ....]

INPUT "xxx",A$ etc
83 + 40 ... 41 + 38 + (string variable expression)

INPUT "xxx",A etc
83 + 40 ... 41 + 39 + (integer variable expression)

FOR statement
FOR I=1 to 10 etc
85 + (integer variable expression) + 86 + (integer expression) + 87 + (integer expression)

FOR I=1 to 10 STEP 2 etc
85 + (integer variable expression) + 86 + (integer expression) + 87 + (integer expression) + 88 + (integer expression)

NEXT statement
89 + (integer vriable expression)

IF statement
IF I=0 then 100 etc
96 + (integer expression) + (22|23|24|25|26|27|28) + 36 + (integer expression | statement)

IF I$="" then 100 etc
96 + (string expression) + (57|58) + (string expression) + 36 + (integer expression | statemet)

PRINT statement
PRINT
99

PRINT A$ etc
97 + (string expression)

PRINT A$; etc
97 + (string expression) + 71

PRINT A$;A$; etc
97 + (string expression) + 70 + ( (string or integer expression) ) [ + 71]   ( 70 follows string: 69 follows integer)

"," ->72 (follows string) or 73 (follows integer)

PRINT A etc
98 + (integer expression) [ + 69 + ( (string or integer expression) ) ] [ + 71]   ( 70 follows string: 69 follows integer)

POKE statement
100 + (integer expression) + 101 + (integer expression)
]]>
Basic Compiler http://www.rad51.net/blog/apple1/?itemid=381 Wed, 04 Jul 2007 17:50:55 PDT ITEM381_20070704