Menu

Tree [842cde] master /
 History

HTTPS access


File Date Author Commit
 asm 2015-12-19 patterson7019 patterson7019 [842cde] Now handles 16-bit result
 docs 2015-07-04 lee lee [0d84bd] Adding documentation to repository
 etc 2015-06-12 lee lee [20e555] updated file perms and included required libs
 lib 2015-06-12 lee lee [20e555] updated file perms and included required libs
 src 2015-12-19 patterson7019 patterson7019 [eefef7] New mnemonics ANMA, ANIA, ORIA, SR. Keyboard ha...
 testasm 2015-08-11 patterson7019 patterson7019 [0d7e49] numbers test works
 README.txt 2015-08-08 lee lee [1ec35c] Describe sample programs.
 build.xml 2015-07-27 lee lee [f8f370] Updated the dist target to automatically create...

Read Me

# SharpiEmu, the Sharp PC-1360 Emulator #

Thanks for checking out SharpiEmu. SharpiEmu is an open source Java based PC-1360 emulator. It can currently emulate 127 out of 133 instructions of the SC61860 CPU. You can also use it as a debugging tool, to step through your code one instruction at a time. It will load binary files generated by, for example, [PockASM](http://www.aldweb.com/articles.php?lng=en&pg=28). The debugger shows the 1360's 150x32 pixel screen, registers, and disassembly. You can step over and into CALL routines.

See the Building and running section below to get right to it, or read on for more background. 

As a side note, I have found that learning assembly on the SC61860 CPU is easier then the Intel and 6809 CPUs. So it's a great stepping stone!

# Objective #
The goal of this project is to make a Java based emulator that can be used for running and debugging Machine Language programs for the PC-1360. The project is a great learning experience, both for learning to write assembly language, and how to write an emulator. I'm not trying to make the best emulator, just one that works, and learn from it. 

Once the emulator core is setup for the PC-1360, the next goal is to emulate other sharp models based on the 8 bit SC61860 CPU. PC-1403 is the next likely candidate.

I had a strong emphasis on building junits right from the start, to ensure the instructions work correctly. For example, when an instruction should modify the zero flag, I have a junit to make sure it does. 


# Building and running #
To compile, you will need [Apache Ant](http://ant.apache.org). You will also need a compile assembly language program, in BIN format. You can use scroll.asm if you like. Note that the scrolling speed will not be consistent with the real hardware, as I am not synching to the speed of the 61860's 768KHz. 

    $ ant dist
    $ java -jar dist/SharpiEmu.jar


You can run the emulator from the command line, or you can double click on the dist/SharpiEmu.jar file to start the emulator.

The emulated 1360 display comes up. From there you:

1. File > Open and locate your .bin file, or you can load scroll.bin or anim1.bin that I have included in the testasm folder. 
2. Specify the load address and execute address, in decimal. Click Ok.
3. Either run the program via Emulator > Run, or Start debugging with Emulator > Debug and step through your code with Emulator > Step Over.

>**Note**: The keyboard and sound are not yet supported. 

>**Also note**: Not all opcodes are supported yet, so if one is found that isn't supported, you will get an error message. 

# Setup PC-1360 for both BASIC and Machine Language programs #

A utility is included to calculate the BASIC `POKE` you need to allow both BASIC and ML programs to coexist without stomping on each other. 

    $ java -cp dist/SharpiEmu.jar axorion.PokeBasic
    Calculate what BASIC's POKE statement should be 
    when allocating memory for ML programs.
    By Lee Patterson http://www.axorion.com
    
    RAM Card Size in KB (8, 16, 32)? [32] 16
    Reserve how many bytes? [8192] 
    Your new start address for BASIC is E030 (57392)
    POKE 65495,48,224
    Press MODE to enter PRO mode
    Enter NEW and go back to RUN mode

Now instead of trying to manually calculate what the POKE will be, you run the PokeBasic util and it tells you exactly what to write.


## Memory layout details ##

For more information see [Where to put Machine Language programs](http://www.aldweb.com/articles.php?lng=en&pg=53).

| RAM Card | Start Address of Basic | End Address of Basic |  
|  ------	| ------	| ------	|  
| 8  Kb    | &E030                  | &F9C9                |
| 16 Kb    | &C030                  | &F9C9                |
| 32 Kb    | &8030                  | &F9C9                |
[PC-1360 BASIC Addresses]

Now, to the Start Address of Basic found from the above table, you will add the amount of bytes that you want to dedicate to ML.
For example, if you want to dedicate 2 Kb (2 * 1024 = 2048 bytes = &800 bytes) on a 16 Kb card, you will calculate : ADR = &C030 + &800 = &C830. Make sure that this number remains smaller than the End Address of Basic as put in the above table. Note that ADR is made of a Low Byte and a High Byte, with ADR = LB + 256 x HB. In our example LB = &30 and HB = &C8.

16KB card, 4KB ML space = &D030

And now, only a few more steps to execute :

1. All Reset your Sharp PC, answer Y to confirm
2. Type POKE &FFD7, &30, &D0 (ADR = LB + 256 x HB), press ENTER to validate line 
2. Type POKE 65495, 48, 208
3. Press MODE key to enter PRO mode
4. Type NEW, press ENTER to validate command
5. Press MODE key again to go back to RUN mode


# The Sharp PC-1360 Pocket Computer #
The Sharp PC-1360 is a small pocket computer manufactured by Sharp in 1987. The 1360 superseded the PC-1350 from 1984, and features one additional RAM expansion port, improved BASIC, floppy disk capability, and a faster CPU. Engineers and programmers like the 1360 for its decent programming and graphical capabilities.

- CMOS 8 bit CPU SC61860 @ 768KHz
- 150x32 pixel LCD controlled by SC43537 Display LSI chip
- 4 KB RAM on 2 * HM6116 chip
- 40 KB System ROM (8 KB cpu internal, 32 KB external on SC613256 chip)
- Integrated piezo speaker (beep only)
- I/O Sharp custom interfaces for printers and tape recorders
- I/O RS-232 at TTL level
- Powered by two CR-2032 lithium batteries (consumption max 5mA during arithmetical computing, 20uA during power off)
- Built-in BASIC interpreter
- RAM expansion port, for up to 64 KB of RAM in total.

# A few useful links #

How to write an emulator. This is the site that got me started on the idea of making an emulator in the first place. 
<http://www.emulator101.com.s3-website-us-east-1.amazonaws.com>

- Pocket Tools, contains 64-bit versions of bin2wav.exe
<http://pocket.free.fr/index.html>

- Service manual 
<https://drive.google.com/file/d/0B9MTQ4daqp4qcDc2cUNfdEJYS3c/edit?pli=1>

- User Manual
<http://pocketcomputerworld.free.fr/Manuals/PC-1360.pdf>

- Machine Language reference
<http://www.aldweb.com/articles.php?lng=en&pg=53>

- Simon's Pocket Computer Resource
<http://www.lehmayr.de/e_pc.htm>


- [Sample assembly program](http://www.axorion.com/?f=blog&pageId=42)

- YASM Assembler, perl
<http://www.oit.ac.jp/bme/~yagshi/misc/pocketcom/yasm-e.html>

- Assembler language reference categorized
<http://shop-pdp.net/ashtml/as6186.htm>

- Short manual for 1360
<http://www.lehmayr.de/PC-1360/e_Manuals/e_Short%20manual%20for%20PC-1360.htm>

- PockEmul module
<https://code.google.com/p/pockemul/source/browse/trunk/src/cpu/sc61860.cpp?r=145>


# Inspirations #
Things that I find inspire this project. 

- Atari 2600
- [Dungeons of Daggorath](https://en.wikipedia.org/wiki/Dungeons_of_Daggorath), one of the first real-time, first-person perspective role-playing video games. It was produced by DynaMicro for the Tandy (RadioShack) TRS-80 Color Computer in 1982. It was distributed on an 8KB ROM cartridge.




# CPU Instructions #
133 instructions. Instruction list pulled from [Aldweb](http://www.aldweb.com/articles.php?lng=en&pg=53), and a [nicely categorized list](http://shop-pdp.net/ashtml/as6186.htm).

    Hex   Dec   Instruction   Function                         Bytes  Cycles  Flags
    &00   000   LII n         n -> I                           2      4
    &01   001   LIJ n         n -> J                           2      4
    &02   002   LIA n         n -> A                           2      4
    &03   003   LIB n         n -> B                           2      4
    &04   004   IX            X + 1 -> X                       l      6
    &05   005   DX            X - 1 -> X                       1      6             
    &06   006   IY            Y + 1 -> Y                       1      6             
    &07   007   DY            Y - 1 -> Y                       1      6             
    &08   008   MVW           I -> d                           1      5+2xd         
    &09   009   EXW           I -> d                           1      6+3xd         
    &0A   010   MVB           J -> d                           1      5+2xd         
    &0B   011   EXB           J -> d                           1      6+3xd         
    &0C   012   ADN           I -> d                           1      7+3xd   C,Z   
    &0D   013   SBN           I -> d                           1      7+3xd   C,Z   
    &0E   014   ADW           I -> d                           1      7+3xd   C,Z   
    &0F   015   SBW           I -> d                           1      7+3xd   C,Z
    &10   016   LIDP nm       n -> DPH ; m -> DPL              3      8
    &11   017   LIDL n        n -> DPL                         2      5
    &12   018   LIP n         n -> P                           2      4
    &13   019   LIQ n         n -> Q                           2      4
    &14   020   ADB           [P+1,P] + (B,A) -> [P+1,P]       1      5       C,Z
    &15   021   SBB           [P+1,P] - (B,A)-> [P+1,P]        1      5       C,Z
    &18   024   MVWB          I -> d                           l      5+4xd
    &19   025   EXWD          I -> d                           1      7+6xd
    &1A   026   MVBD          J -> d                           1      5+4xd
    &1B   027   EXBD          J -> d                           1      7+6xd
    &1C   028   SRW           I -> d                           1      5+1xd
    &1D   029   SLW           I -> d                           1      5+1xd
    &1E   030   FILM          I -> d                           1      5+1xd
    &1F   031   FILD          I -> d                           1      4+3xd
    &20   032   LDP           P -> A                           1      2
    &21   033   LDQ           Q -> A                           1      2
    &22   034   LDR           R -> A                           1      2
    &23   035   RA            0 -> A                           1      2
    &24   036   IXL           X + 1 -> X                       1      7
    &25   037   DXL           X - 1 -> X                       1      7
    &26   038   IYS           Y + 1 -> Y                       1      6
    &27   039   DYS           Y - 1 -> Y                       1      6
    &28   040   JRNZP n       if Z=0                           2      7/4
    &29   041   JRNZM n       if Z=0                           2      7/4
    &2A   042   JRNCP n       if C=0                           2      7/4
    &2B   043   JRNCM n       if  C=0                          2      7/4
    &2C   044   JRP n         PC + 1 + n -> PC                 2      7
    &2D   045   JRM n         PC + 1 - n -> PC                 2      7
    &2F   047   LOOP n        [R] - 1 -> [R]                   2      10/7
    &30   048   STP           A -> P                           1      2
    &31   049   STQ           A -> Q                           1      2
    &32   050   STR           A -> R                           1      2
    &34   052   PUSH          R - 1 -> R                       1      3
    &35   053   DATA          I -> d                           l      11+4xd
    &37   055   RTN           [R,R+1] -> PC                    l      4
    &38   056   JRZP n        if Z=1                           2      7/4
    &39   057   JRZM n        if Z=1                           2      7/4
    &3A   058   JRCP          if C=1                           2      7/4
    &3B   059   JRCM          if C=1                           2      7/4
    &40   064   INCI          I + 1 -> I                       1      4       C,Z
    &41   065   DECI          I - 1 -> I                       l      4       C,Z
    &42   066   INCA          A + 1 -> A                       l      4       C,Z
    &43   067   DECA          A - 1 -> A                       1      4       C,Z
    &44   068   ADM           [P] + A -> [P]                   l      3       C,Z
    &45   069   SBM           [P] - A -> [P]                   1      3       C,Z
    &46   070   ANMA          [P] and A -> [P]                 1      3       Z
    &47   071   0RMA          [P] or A -> [P]                  1      3       Z
    &48   072   INCK          K + 1 -> K                       1      4       C,Z
    &49   073   DECK          K - 1 -> K                       1      4       C,Z
    &4A   074   INCM          M + 1 -> M                       l      4       C,Z
    &4B   075   DECM          M - 1 -> M                       1      4       C,Z
    &4C   076   INA           IA-Port -> A                     1      2
    &4D   077   NOPW          No Operation                     l      2
    &4E   078   WAIT n        No Operation                     2      6+n
    &4F   079   WAITI         No Operation                     1      5+4xd
    &50   080   INCP          P + 1 -> P                       l      2       C,Z
    &51   081   DECP          P - 1 -> P                       l      2       C,Z
    &52   082   STD           A -> [DP]                        1      2
    &53   083   MVDM          [P] -> [DP]                      1      3
    &54   084   READM         [PC+1] -> [P]                    1      3
    &55   085   MVMD          [DP] -> [P]                      l      3
    &56   086   READ          [PC+1] -> A                      1      3
    &57   087   LDD           [DP] -> A                        1      3
    &58   088   SWP           A <- swap bits [1-4]<->[5-8]     1      2
    &59   089   LDM           [P] -> A                         1      2
    &5A   090   SL            A <- 1 bit shift left            1      2       C
    &5B   091   POP           [R] -> A                         1      2
    &5D   093   OUTA          [5C] -> IA-Port                  1      3
    &5F   095   0UTF          [5E] -> FO-Port                  l      3
    &60   096   ANIM n        [P] and n -> [P]                 2      4       Z
    &61   097   ORIM n        [P] or n -> [P]                  2      4       Z
    &62   098   TSIM n        [P] and n -> Z                   2      4
    &63   099   CPIM n        [P] - n -> C,Z                   2      4       C,Z
    &64   100   ANIA n        A and n -> A                     2      4       Z
    &65   101   ORIA n        A or n -> A                      2      4       Z
    &66   102   TSIA n        A and n -> Z                     2      4
    &67   103   CPIA n        A - n -> C,Z                     2      4       C,Z
    &69   105   DTJ           Do Table Jump                    -      -
    &6B   107   TEST n        n -> TEST                        2      4       Z
    &70   112   ADIM n        [P] + n -> [P]                   2      4       C,Z
    &71   113   SBIM n        [P] - n -> [P]                   2      4       C,Z
    &74   116   ADIA n        A + n -> A                       2      4       C,Z
    &75   117   SBIA n        A - n -> A                       2      4       C,Z
    &78   120   CALL nm       PC + 3 -> [R-1,R-2]              3      8
    &79   121   JP nm         nm -> PC                         3      6
    &7A   122   PTJ           Prepare Table Jump               4      9
    &7C   124   JPNZ nm       if Z=0                           3      6
    &7D   125   JPNC nm       if C=0                           3      6
    &7E   126   JPZ nm        if Z=1                           3      6
    &7F   127   JPC nm        if C=1                           3      6
    &80   128   LP l          l -> P                           1      2
    &C0   192   INCJ          J + 1 -> J                       1      4       C,Z
    &C1   193   DECJ          J - 1 -> J                       1      4       C,Z
    &C2   194   INCB          B + 1 -> B                       1      4       C,Z
    &C3   195   DECB          B - 1 -> B                       1      4       C,Z
    &C4   196   ADCM          [P] + A + C -> [P]               1      3       C,Z
    &C5   197   SBCM          [P] - A - C -> [P]               1      3       C,Z
    &C6   198   TSMA          [P] and A -> Z                   1      3
    &C7   199   CPMA          [P] - A -> C,Z                   1      3       C,Z
    &C8   200   INCL          L + 1 -> L                       1      4       C,Z
    &C9   201   DECL          L - 1 -> L                       1      4       C,Z
    &CA   202   INCN          N + 1 -> N                       1      4       C,Z
    &CB   203   DECN          N - 1 -> N                       1      4       C,Z
    &CC   204   INB           IB-Port -> A                     1      2
    &CE   206   NOPT          No Operation                     1      3
    &D0   208   SC            1 -> C                           1      2       C,Z
    &D1   209   RC            0 -> C                           1      2       C,Z
    &D2   210   SR            A <- 1 bit shift right           1      2       C
    &D4   212   ANID n        [DP] and n -> [DP]               2      6       Z
    &D5   213   ORID n        [DP] or n -> [DP]                2      6       Z
    &D6   214   TSID n        [DP] and n -> Z                  2      6
    &D8   216   LEAVE         0 -> [R]                         1      2
    &DA   218   EXAB          A <-> B                          1      3
    &DB   219   EXAM          A <-> [P]                        1      3
    &DD   221   0UTB          [5D] -> IB-Port                  1      2
    &DF   223   0UTC          [5F] -> Control Port             1      2
    &EO   224   CAL ln        PC + 2 -> [R-1,R-2]              2      7

# Keyboard #

You can call the internal ROM keypressed function with:

                call    7836

Carry flag set when a key was pressed. A register contains the key pressed.

For example:

    presskey        equ     7836        # @ of internal ROM KeyPressed function
    
                    jp      start
                    
    result:         db      0
    
    start:          call    presskey
                    jpnc    start
                    lidp    result
                    std
    end:            rtn
    
For more information see [INKEY$ in Machine Language](http://www.aldweb.com/articles.php?lng=en&pg=54).


# Example Assembly Programs #

There are a number of samples in the testasm directory. I'll list the important ones. The others are just one off's to test an instruction on the actual hardware. 

| File | Description |
| --- | --- |
| anim1.asm | Animated Lemming.  |
| scroll.asm | Sample scrolling splash screen.  |
| scroll.bin | Binary file, compiled from scroll.asm  |
| scroll2.asm | Scrolls a map across the screen contunuously by wrapping .  |
| setpixel-video.asm | Set a pixel in video memory.  |
| PETOOLS.asm | PETOOLS |
| WIN13x0.asm | Aldweb example that comes with PockASM |
| add.asm | |
| add.bas | |
| array.asm | Sample from tutorial  |
| callcompare.bas | BASIC source for sample  |
| callrev.bas | BASIC source for sample  |
| compare1.asm | Sample from tutorial  |
| dbuffer.asm |   |
| indexTest.asm |   |
| letters.asm | Graphical Hello World example. Created small font that is able to render 37x5 characters instead of the standard 25x4.  |
| math.asm | 8-bit multiple and divide routines  |
| reverse.asm | Sample from tutorial  |
| screen1.asm |   |
| screen2.asm |   |
| screen3.asm |   |
| splash.asm | Displays a splash screen.  |
| tohex.asm | Example of converting a decimal number to hex ascii.  |