blog to enjoy apple1 replica

Jeans & Development 電子ブロック工房 三日坊主 フロントページ

Debbuged print routine [Basic Compiler]

2007年10月16日

The print routine was debugged.

Debbuged print routine works fine.

OK. Let's go to string variable and substring routines.

BASIC compiler [Basic Compiler]

2007年10月4日

The array routine was completed today.

array

Mmm...there is a bug around PRINT routine, however, putting value to array and getting value from array work well!

Using stack in BASIC [BASIC]

2007年9月17日

Apple BASIC doesn't support user-defined function. All variables are therefore global ones. If some variables are used in sub routine (that can be called by GOSUB statement), the variables are of course modified in the sub routine. Following way avoids this problem.

stack

Lines 1010 and 1060 correspond to PUSH and POP commands, respectively.

Flash writer for Replica I [Serial EEPROM]

2007年9月16日

I made a serial EEPROM writer for Replica I, which uses 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

Indirect JMP [6502]

2007年8月17日

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.

JSR command [6502]

2007年8月5日

After executing JSR command of 6502, higher 8 bit data is first pushed to stack, then lower 8 bit data is pushed.
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.

Div routine [Basic Compiler]

2007年7月31日

Revised dividing code follows:
* = $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.

Math calc routine [Basic Compiler]

2007年7月10日

Mathematical calculation routines. Two input values must be put into $1000 - $1003. Note that the addresses, $1000 - $1007 are not static but dinamically set by compiler. Result will be put into X and Y resisters (X+Y*256).

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.

Integer and string [Basic Compiler]

2007年7月4日

Integer may contain:

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

Statements [Basic Compiler]

2007年7月4日

Apple Basic allows following statements in program

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
<<前の記事