Hijacking the P2-EVAL ROM

While I just was thinking about how nice the build in Monitor/Debugger works and one can switch between Monitor and TAQOZ, I stumbled about TAQOZ doing a cold start all the time I switched between Monitor and TAQOZ.
Not nice, I just had finally some words defined, hit ctrl-D use the monitor, hit ESC cr, back in TAQOZ, my words are gone.

That was, what started this.

I needed to patch the ROM that @Cluso99 's monitor/debugger on ESC cr NOT jumps to _START_TAQOZ but to _REENTER_TAQOZ and voila, my words stay alive.

That got me thinking what else could I patch into the ROM that might be useful.

And looking thru the ROM source I decided to try to Hijack the complete thing. Sure none of this will work on the next ROM, but it can be adapted.

Most of it is changing rx and tx port numbers away from the usb-port, so that stays free for the user application. It would be nice if the next ROM could spare two longs for rx/tx pins instead of hardcoding it into every instruction with #rx_pin.

compared to current it would save a lot of patching, just 2 longs not xxx places in the ROM code.


ok lets start with some code
' This program creates an 4-LED Larson scanner on the P2 Eval board

ls_fwd  mov 	ledpin, 	#56     ' start with p56
        mov 	cycles, 	#3      ' light 4 going up
.loop   drvl    ledpin          	' led on
        waitx   ##_clockfreq/8  	' wait 1/8 second
        drvh    ledpin          	' led off
        add 	ledpin, 	#1      ' next pin
        djnz    cycles, 	#.loop  ' done? 

ls_rev  mov 	ledpin, 	#59     ' start with p60
        mov 	cycles, 	#3      ' light 4 going down
.loop   drvl    ledpin
        waitx   ##_clockfreq/8
        drvh    ledpin
        sub 	ledpin, 	#1
        djnz    cycles, 	#.loop

        jmp 	#ls_fwd

ledpin  res 1
cycles  res 1

Since I want serial coms to the ROM I need some frequency, so I use @Cluso99 method to calculate as constants and switch to it, then start a new COG with my Larson.

Basically I just add the launch code in front of the PASM and change orgh to greater as $FFFF
CON
  _XTALFREQ     = 20_000_000                                    ' crystal frequency
  _XDIV         = 4             '\                              '\ crystal divider                      to give 5.0MHz
  _XMUL         = 72            '| 180MHz                       '| crystal / div * mul                  to give 360MHz
  _XDIVP        = 2             '/                              '/ crystal / div * mul /divp            to give 180MHz
  _XOSC         = %10                                   '15pF   ' %00=OFF, %01=OSC, %10=15pF, %11=30pF
  _XSEL         = %11                                   'XI+PLL ' %00=rcfast(20+MHz), %01=rcslow(~20KHz), %10=XI(5ms), %11=XI+PLL(10ms)
  _XPPPP        = ((_XDIVP>>1) + 15) & $F                       ' 1->15, 2->0, 4->1, 6->2...30->14
  _CLOCKFREQ    = _XTALFREQ / _XDIV * _XMUL / _XDIVP            ' internal clock frequency                
  _SETFREQ      = 1<<24 + (_XDIV-1)<<18 + (_XMUL-1)<<8 + _XPPPP<<4 + _XOSC<<2  ' %0000_000e_dddddd_mmmmmmmmmm_pppp_cc_00  ' setup  oscillator
  _ENAFREQ      = _SETFREQ + _XSEL                                             ' %0000_000e_dddddd_mmmmmmmmmm_pppp_cc_ss  ' enable oscillator
'------------------------------------------------------------------------------------------------
  _baud         = 2_000_000'115_200
  _bitper       = (_clockfreq / _baud) << 16 + 7          	' 115200 baud, 8 bits
  _SerialInit   = $fcab8        				' Serial Initialise     (lmm_x & lmm_bufad must be set first)
  _HubMonitor   = $fcd78        				' Calls the Monitor; uses lmm_bufad as the input buffer address
  _HUBBUF       = $FC000        				' overwrite Booter as serial buffer
  _START_TAQOZ  = $FD028

  lmm_x         = $1e0          				' parameter passed to/from LMM routine (typically a value)
  lmm_bufad     = $1ef          				'_HubRxString
'------------------------------------------------------------------------------------------------
DAT
        orgh    0
        org     0

        hubset  #0                              ' set 20MHz+ mode
        hubset  ##_SETFREQ                      ' setup oscillator
        waitx   ##_XTALFREQ/100                	' ~10ms
        hubset  ##_ENAFREQ                      ' enable oscillator

	' patch ROM
	' _REENTER_TAQOZ not _START_TAQOZ on ESC cr
        wrbyte	#$B4,		  ##$FCD8C   	' new - if_e    jmp     #@_REENTER_TAQOZ
						' old - if_e    jmp     #@_START_TAQOZ

	' now start
        mov     lmm_bufad,        ##_HUBBUF     ' locn of hub buffer for serial routine 
        mov     lmm_x,            ##_bitper     ' sets serial baud
        call    #_SerialInit                    ' initialise serial
	
        'SETQ    ptra_val           		' would end up in ptra of new cog
        coginit #1,##@_mainprogram              ' Start Main program in COG #1

	jmp	#_START_TAQOZ			' and transfer control of COG 0 to TAQOZ
 
        fit     $1E0                    	' ensure LMM reserved area cog $1E0-$1EF available                                                                              
''---------------------------------------------------------------------------------------------------
        orgh    $10000              		' leave the first 64K free for TAQOZ
        org 0
_mainprogram
''---------------------------------------------------------------------------------------------------
'' HERE NOW THE SOURCE OF WHATEVER YOU WANT TO PLAY WITH (it will run on COG #1++)
''---------------------------------------------------------------------------------------------------

' This program creates an 4-LED Larson scanner on the P2 Eval board

ls_fwd  mov 	ledpin, 	#56     ' start with p56
        mov 	cycles, 	#3      ' light 4 going up
.loop   drvl    ledpin          	' led on
        waitx   ##_clockfreq/8  	' wait 1/8 second
        drvh    ledpin          	' led off
        add 	ledpin, 	#1      ' next pin
        djnz    cycles, 	#.loop  ' done? 

ls_rev  mov 	ledpin, 	#59     ' start with p60
        mov 	cycles, 	#3      ' light 4 going down
.loop   drvl    ledpin
        waitx   ##_clockfreq/8
        drvh    ledpin
        sub 	ledpin, 	#1
        djnz    cycles, 	#.loop

        jmp 	#ls_fwd

ledpin  res 1
cycles  res 1


Now Larson runs on COG1 and TAQOZ on COG0 using USB to PC.

that made me interested, so I dug in deeper...

Mike
I am just another Code Monkey.
A determined coder can write COBOL programs in any language. -- Author unknown.
Press any key to continue, any other key to quit

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this post are to be interpreted as described in RFC 2119.

Comments

  • Now my goal is to use all the mighty of the ROM build in TAQOZ from other more readable languages. Like one can dedicate a job to a smart pin, one can dedicate a job to a TAQOZ smart core.

    And it works. I can basically 'talk' to TAQOZ or the MONITOR/DEBUGGER via serial. To leave the standard serial port for the normal application I needed to convince the current ROM routines to listen and write to different pins, but this was doable by patching the ROM.

    except 'lsio'

    that sort of resets the rx/tx pins and kills me.

    Anyways, it is working, sort of.

    I patch the ROM to use different pins, then I patch the rx smartpin of the ROM to listen to the pin next to itself. Same for my connecting driver, it also listen to the pin next to it. Those smart pins are cool.

    OK,

    now I have COG0 running TAQOZ/MONITOR, 4 pins to communicate and everything else free.

    But it is a tedious process, compiling with fastspin, opening the P2ASM file, inserting the block of code directly at the first DAT line, changing orgh $800 against orgh $10800. On every compile.

    attached some source to compile and run, created with fastspin and modified a bit...

    you can compile it and load it with whatever you have, it is just PASM

    I need some buffered serial smart pin driver to get this usable.

    Enjoy!

    Mike
    I am just another Code Monkey.
    A determined coder can write COBOL programs in any language. -- Author unknown.
    Press any key to continue, any other key to quit

    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this post are to be interpreted as described in RFC 2119.
  • Now you get an idea how hard it was in testing our ROM code, and we were up against the time barrier and ROM space. We had to cull the code to make it fit. But Peter and I had fun :smiley:
    My Prop boards: P8XBlade2, RamBlade, CpuBlade, TriBlade
    Prop OS (also see Sphinx, PropDos, PropCmd, Spinix)
    Website: www.clusos.com
    Prop Tools (Index) , Emulators (Index) , ZiCog (Z80)
  • yes @Cluso99

    I really like the work you did with the Monitor and serial routines. The TAQOZ part is less understandable...

    Mike
    I am just another Code Monkey.
    A determined coder can write COBOL programs in any language. -- Author unknown.
    Press any key to continue, any other key to quit

    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this post are to be interpreted as described in RFC 2119.
  • Hi msrobots,

    What did you mean by hijacking? Did you manage to rewrite the ROM?

    Kind regards, Samuel Lourenço
  • He means patching.
    Of course you can replace it entirely.
    My Prop boards: P8XBlade2, RamBlade, CpuBlade, TriBlade
    Prop OS (also see Sphinx, PropDos, PropCmd, Spinix)
    Website: www.clusos.com
    Prop Tools (Index) , Emulators (Index) , ZiCog (Z80)
  • evanhevanh Posts: 6,405
    edited 2019-01-18 - 15:05:07
    because it sits in hubRAM, unlike the Prop1.

    The physical ROM storage is not executable, there is a special few hardwired instructions, in cog0 only, that copy it into hubRAM on power up ... Or something like that.

    "There's no huge amount of massive material
    hidden in the rings that we can't see,
    the rings are almost pure ice."
  • evanh wrote: »
    because it sits in hubRAM, unlike the Prop1.

    The physical ROM storage is not executable, there is a special few hardwired instructions, in cog0 only, that copy it into hubRAM on power up ... Or something like that.
    Ah, I see. So, he only altered the copy in RAM (which is a feat by itself). I was finding strange that you could change the ROM (because after all it could be an EEPROM). It the ROM could be altered, that could render the P2 unusable.

    Kind regards, Samuel Lourenço
  • Cluso99 wrote: »
    He means patching.
    Of course you can replace it entirely.

    No by hijacking I meant using the build in ROM (especially TAQOZ, but also the MONITOR) by talking to it as serial device on some other pins then 63/62.

    The goal here is to be able to 'program' TAQOZ from say SPIN or BASIC or Assembler or C by using it as serial device (supported by all languages) sending TAQOZ one liners to the serial port and receiving results via serial port. Just like using it now from a Terminal, but have your program type the commands and read the response.


    Enjoy!

    Mike
    I am just another Code Monkey.
    A determined coder can write COBOL programs in any language. -- Author unknown.
    Press any key to continue, any other key to quit

    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this post are to be interpreted as described in RFC 2119.
  • msrobots wrote: »
    Cluso99 wrote: »
    He means patching.
    Of course you can replace it entirely.

    No by hijacking I meant using the build in ROM (especially TAQOZ, but also the MONITOR) by talking to it as serial device on some other pins then 63/62.

    The goal here is to be able to 'program' TAQOZ from say SPIN or BASIC or Assembler or C by using it as serial device (supported by all languages) sending TAQOZ one liners to the serial port and receiving results via serial port. Just like using it now from a Terminal, but have your program type the commands and read the response.


    Enjoy!

    Mike
    The Monitor can be patched for the serial pins. There are 10 instructions in the ROM requiring this.

    AFAIK TAQOZ probably cannot be easily patched as the next version will be compressed. While it would be nice to feed one-liners to TAQOZ I don't know if this is possible. Peter?
    My Prop boards: P8XBlade2, RamBlade, CpuBlade, TriBlade
    Prop OS (also see Sphinx, PropDos, PropCmd, Spinix)
    Website: www.clusos.com
    Prop Tools (Index) , Emulators (Index) , ZiCog (Z80)
Sign In or Register to comment.