Designing cross-compatible programs for Model 100 to NEC 8201A/8300.
1. Screen location: Instead of using the PRINT@nn, or LOCATE X,Y conventions, use the VT-52
escape sequence which is completely universal to both platforms. You could create a little
routine like this:|
50000 PRINTCHR$(27)"Y"CHR$(32+Y)CHR$(32+X);:RETURNYou would use it like this:
100 X=5:Y=2:GOSUB50000:PRINT"Isn't that simple?"2. Graphics: In general, things are already pretty compatible. PSET and PRESET works on both platforms, and LINE(X,Y)-(X1,Y1) statements on the NEC require that LINE.CO is installed. The NEC has a customizable graphics character set, unlike the Model 100 which has them hardcoded in ROM. A simple installation of CHR100.CO and the Model 100 CHR$(131)-CHR$(255) are now available on the NEC.
3. Keyboard interrupts: Don't use the ON KEY GOSUB, KEYON and KEYOFF keywords, as they are Tandy specific. What you can do instead is poll the keyboard using INKEY$ and check for the key value, and branch manually to the subroutines desired. You could make a subroutine that does this that you simply call at various places in the main program loop.
4. VARPTR: While this is part of Tandy's Basic, it isn't supported by N82 Basic. But, for the NEC it can be implemented through a routine like this:
40000 H=0:L=0:TY=0 40010 POKE64448,205:POKE64449,175:POKE64450,73:POKE64451,235 40020 POKE64452,58:POKE64453,139:POKE64454,250:POKE64456,201 40030 IFVY$=""THENPRINT"VY$ not defined!":STOP 40040 FORH=64457TO64463:POKEH,ASC(MID$(VY$,H,1)+CHR$(0)):NEXT:POKE64464,0 40050 POKE63912,201:POKE63913,251:EXEC64448 40060 L=PEEK(63912!):H=PEEK(63913!):TY=PEEK(63911!) 40070 RETURN 40080 ' VARPTR by Gary Weber 40090 ' Entry: VY$ must contain the name of variable of interest 40100 ' Exit: H & L contain variable's address, TY contains type 40110 ' Example: 40120 ' 100 A$="This is a sample string." 40130 ' 110 VY$="A$":GOSUB 40000 40140 ' 120 PRINT "VARPTR of ";VY$;" is ";L+(H*256)
5. POKEs and PEEKs: Use memory maps (nec.map, m100.map) and the NEC/100 cross reference (NEC100.DAT), all available in the Technical Documents area of this web site. Since these addresses are machine specific, just detect the machine type using the PEEK(1) statement (148=NEC, 51=M100), and use the appropriate addresses for the RAM & ROM locations.
6. CALLs and EXECs: This is a little more tricky. Model 100 BASIC uses the "CALL" statement and NEC uses "EXEC". Based on your detected machine type with PEEK(1), use the appropriate statement along with the specific address for your machine as referenced from the NEC & M100 memory maps & cross reference. Also, the M100's CALL syntax allows passing of values to place in the A and HL registers. The NEC's EXEC statement only takes one parameter, which is the entry address. However, there are special locations in NEC's upper memory "bookkeeping" area which are used to pass the A, L, and H register values to EXEC. Before you issue the EXEC
7. Embedded machine language would need to be assembled for each platform and the M100 and NEC specific routines would be called based on the PEEK(1) machine type.
8. MID$ as an assignment is not supported in N82 basic. You can only use the MID$ statement to extract characters from a string. However, on the NEC you can simulate the function of a MID$ assignment with a routine like this:
30000 ZO=LEN(OX$):TX$=OX$:OX$=LEFT$(TX$,NX-1)+NX$ 30010 IFZO-LEN(OX$)>0THENOX$=OX$+RIGHT$(TX$,ZO-LEN(OX$)) 30020 OX$=LEFT$(OX$,ZO):RETURN 30030 ' MID$ by Gary Weber 30040 ' Entry: OX$=String to modify, NX=Target position, NX$=Target text 30050 ' Exit: OX$ contains modified string