PpHd> GLD marche par les trucs compilés avec AS ?
(donc sans info d debug et tout, je penses)
include "RomCalls.h"
; Define it to have the HW2-TSR version
;hw2tsr set 1
; Do not define it to call every program (even nostub program) with Shift+on
ShiftOnKernel set 1
; To Do:
; Gestion flags: always call exit / compress reloc / new_bss
; kernel::exec_from_scrach(HANDLE d0)
; Permet de liberer de la memoire en liberant le programme courant (ainsi que
; ses librairies.). A la fin du programme execute, on reappelle le 1er programme
; avec les memes registres que lorsqu'il a appelle cette fonction sauf a7.
; Lors de l'appel :
; Preserve les registres d0-d7/a0-a6
; Unrelloc le programme courant (pb si le programme appellant etait archive
; et si tios a fait une copie...)
; Push Nom complet du programme appellant (HSymToName(Hd2Sym(Ptr2Sym(return addr))))
; Relecture d0.
; Appel kernel::exec
; Pop Handle
; Reallocation du handle du programme
; Relecture registres.
; Correction adresse de retour
; Retourne a l'adresse de retour (corrigee !)
;
; Base de registres (DataBase) : fichier gerer par le kernel (Archivage automatique).
; kernel::SaveDataBase(In: a0 -> Name, d0.w = Len, a1-> data)
; Sauve les données a1 dans la base de données du kernel sous le nom Name. (Base de registre)
; Ex: x = 23;
; kernel::DataBaseSave("apps/runc/pk92",sizeof(short),&x);
; Now : apps/runc/pk92 = 23
; kernel::LoadDataBase(In: a0 -> Name, d0.w = Len, a1-> data)
; Charge les données depuis la clef a0 dans un buffer de taille d0
; Ex: kernel::DataBaseLoad("apps/runc/pk92",sizeof(short),&x)
; Now x = 23
; Bugs:
; Bug avec txtrider
; Rectangle plein en C qui devient un rectangle vide
; Pb link apres Hot-Reset
; Pb de contraste
xdef _ti89
xdef _ti92plus
xdef _nostub
VERSION_OFFSET EQU $10 ; Offset of the version number
HW2TSR_PATCH MACRO ; An register / Dn register
ifd hw2tsr
exg 1,2 ; Exchange register
bset.l #18,2 ; In the ghost space
exg 2,1 ; Exg register
endif
ENDM
_main:
; Test if the call is from Ti-Home
cmp.l #$200000,(a7)
bls dont_install
ifd hw2tsr
include "hw2tsrh220xtsr.h"
endif
movem.l d3-d7/a2-a6,-(a7)
; Test presence kernel...
lea already(Pc),a0
tst.w ($30).w ; Regarde si un kernel est déjà installé
bne exit
; 0 : Detection of Calc / Hardware and RomBase
; Detection of calc
move.l ($c8).w,d0
andi.l #$600000,d0
move.l d0,a4 ; Rom_base
move.l 260(a4),a1 ; HardwareParmBloc
move.w (a1)+,d1 ; Read and skip size
move.l (a1)+,d2 ; Read Calculator ( 1 : 92+ / 3 : 89 / V200 : ?)
move.l (a1)+,d3 ; Read hardware version
addq.l #1,d3 ; Get Hardware version
; Vti detection by JM
trap #12 ; enter supervisor mode.
move.w #$3000,sr ; set a non-existing flag in sr
move.w sr,d1
move.w d0,SR
moveq #1,d0 ; 92+ Version
btst #12,d1 ; this non-existing flag can only be set on the VTI
beq.s real_calc
moveq #1,d3 ; HW1
cmp.l #$400000,a4
beq.s did
moveq #0,d0 ; 89
bra.s did
real_calc
; Translate calculator from Ti format to kernel format
subq.w #1,d2 ; Yes
beq.s did
moveq #0,d0 ; 89
subq.w #2,d2
beq.s did ; Yes
moveq #3,d0 ; V200
did
;1 : Copy 89/92-v200 values and save calc/hardware
lea valeursRAMti89(pc),a0
lea Calc(pc),a5
move.b d0,(a5)+ ; Save Calculator
beq.s ti89
lea valeursRAMti92(pc),a0
ti89 move.b d3,(a5) ; Save Hardware Version
lea RAM_TABLE+4(pc),a6
moveq #12,d0
copieRAM: move.l (a0)+,(a6)+
dbf d0,copieRAM
move.l a4,-4*11(a6) ; Save Rom_Base
;2 : détermine FontMedium et ReturnValue
fontloop: cmp.l #$54A854A8,(a4)+
bne.s fontloop
subq.l #4,a4
move.l a4,(a6)+
clr.l (a6)+ ;ReturnValue est determinee plus tard
;3 : trouve tios::kb_vars
moveq #6,d0 ; 6 = Key Queue address
trap #9 ; Appel Systeme
lea ($6-$1C)(a0),a0 ; Correction -> kb_vars
move.l a0,(a6)+
; 3' : Trouve tios::statut
ROM_PTR ST_precision
move.w 6(a0),d0
addq.w #3,d0
lea Statut+3(Pc),a1
move.b Calc(Pc),d1
addq.b #1,d1
move.b d1,(a1)+ ; Bit : 1 for 89 / 2 for 92+
move.w d0,(a1) ; Statut ADR
;4 : Trouve Heap
ROM_PTR HeapDeref
heap_loop cmp.w #$2078,(a0)+
bne.s heap_loop
movea.w (a0),a0
move.l a0,(a6)+ ; tios::Heap
;5 : Trouve main, son handle, l'handle de FolderListHandle
pea main_str_end(Pc)
ROM_CALL SymFindHome
move.l d0,d1
clr.w d1
swap d1
move.l d1,(a6)+ ; FolderHandle
move.l d0,(a7)
ROM_CALL DerefSym
addq.l #4,a7
move.w SYM_ENTRY.hVal(a0),d0 ;MainHandle
moveq #0,d1
move.w d0,d1
move.l d1,(a6)+ ; MainHandle
;6 : trouve la version de la ROM et convertit
; Par Kevin Kofler (Modifie par PpHd)
move.l ($c8).w,a1
move.l #$1100,d1 ; Version : Ti-92+ Rom 1.00
move.l -4(a1),d2 ; Get number of ROM CALLS
cmp.l #cmd_table,d2 ; Check if cmd_table is defined
bcs.s save ; Rom Call cmd_table isn't defined : ROM 1.00
move.l cmd_table*4(a1),a0
lea -$10(a0),a0 ; Get address of AMS version
cmpi.l #$440,d2 ; Check if AMS version ROM_CALL is present
bls.s getversion
move.l $440*4(a1),a0 ; Get address of AMS version ROM_CALL
getversion:
moveq #$30,d0
move.b Calc(Pc),d1
lsl.w #4,d1
add.b (a0),d1
sub.b d0,d1
lsl.w #4,d1
addq.l #2,a0
add.b (a0)+,d1
sub.b d0,d1
lsl.w #4,d1
add.b (a0)+,d1
sub.b d0,d1
save: move.l d1,(a6)+
ifnd hw2tsr
;7 : hardware 2 ?
move.b Hw(pc),d0
subq.b #1,d0
ble.s _hw1
; Test presence HW2Patch sur Rom 2.0x par KK
move.l ($c8).w,a0 ; Check AMS 2.0x
cmp.l #1000,-4(a0) ; Check if > 1000 entries
bcs.s _hw1
ROM_PTR EX_stoBCD ; Well, the function which follows EX_stoBCD is the protect function
tst.w 92(a0) ; Check for HW2Patch (ROM resident)
beq.s _hw1 ; Ok, there is HW2 Patch
cmp.l #$100,($ac).w ; Check for HW2Patch (RAM resident)
beq.s _hw1 ; Ok, there is HW2 Patch (Trap B is intercepted)
lea hw2patch(Pc),a0
bra exit
_hw1:
endif
; Gestion EV_hook
ROM_PTR EV_hook
lea EV_hook1+2(pc),a1
move.l a0,(a1)
move.l a0,EV_hook2-EV_hook1(a1)
move.l a0,EV_hook3+2-EV_hook1(a1)
move.l a0,EV_hook4-EV_hook1(a1)
; gestion idle
ROM_PTR idle
lea idleN+2(pc),a1
move.w 2(a0),(a1) ; get idle number identification
; Gestion valeur contraste initiale
moveq #4,d0
trap #9
lea orgcontrast+3(Pc),a1
move.b (a0),d0
subq.b #1,d0
move.b d0,(a1)
; Recherche de valeurs necessaires au nostub anti-crash
ROM_PTR ER_success ; Get ER_success ptr
lea ErrorFrameAdr+2(pc),a1
move.w 2(a0),d0
move.w d0,(a1)
move.w d0,ErrorFrameAdr2-ErrorFrameAdr(a1)
move.w d0,ErrorFrameAdr3-ErrorFrameAdr(a1)
move.w #$4400,d0
move.l ($c8).w,a0 ; Check AMS 2.0x
cmp.l #1000,-4(a0) ; Check if > 1000 entries
bcs.s _ams1
move.w #$4200,d0
_ams1 lea StackPtr+2(Pc),a1
move.w d0,(a1)
; move.l #$0F96A5F0,d1
; ROM_PTR EV_centralDispatcher
;not_found subq.l #2,a0
; cmp.l (a0)+,d1
; bne.s not_found
; lea CentralPatch+6(Pc),a1
; move.w (a0),(a1)
; ROM_PTR FirstWindow
; lea FirstWin+2(Pc),a1
; move.w a0,(a1)
; Recherche de trois fonctions d'AMS cachees
; Attention, c'est assez complique a trouver (mais indispensable).
; Un clr.l FirstWindow n'est pas suffisant sur AMS 2.03.
; C'est pour ca que je recherche ces fonctions !
move.l ($C8).w,d0
andi.l #$600000,d0
add.l #$012088+4,d0
move.l d0,a1
move.l (a1),a1 ; Read Reset vector
; The searched code looks like
; move.l #$DEADDEAD,$4200
; clr.l $5D86
; bsr.s
; bsr.s
; bsr.s
; bsr.s
; bsr.s
; bsr.s
; bsr.s +$36 ; The first function we search
; move.w #$00,SR
; jmp tios::EV_CentralDispatcher
search_dead:
subq.l #2,a1
cmp.l #$DEADDEAD,(a1)+
bne.s search_dead
ROM_PTR EV_centralDispatcher
search_EV
subq.l #2,a1
cmp.l (a1)+,a0
bne.s search_EV
move.l ($41248C-$412462+2)(a1),a1 ; The searched function is in a1
; Now it looks like
;link a6
;tst.l $5D7C
;bne.s
;jsr $ ; The 1st : Reset a flag (I don't know what it does !)
;jsr $ ; The 2nd : Reset PortRestore / SetCurrentClip / ScreenClear(:() / FontSetSys + Some flags
;jsr $ ; The 3rd : Reset the window list + Some Flags
lea AMS_HiddenFunc+2(Pc),a0
move.l 12+6(a1),(a0) ; Read the 2nd function.
move.l 12+6+6(a1),6(a0) ; Read the 3rd function.
;9 : recopie le résultat
pea (blocfin-bloc).w
ROM_CALL HeapAllocHigh
addq.l #4,a7
tst.w d0
bne.s inst
lea memory(Pc),a0
bra exit
inst lea $40030,a6
move.w #$FF54,(a6)+ ;$30=version + $FF pour protection contre le jsr /jmp $0
move.w #'PO',(a6)+ ;$32=identifiant
move.w d0,$14(a6) ; $48=handle du bloc
move.w d0,-(a7)
ROM_CALL HeapDeref ; Adresse du bloc en a0
addq.l #2,a7 ; 2+4
HW2TSR_PATCH a0,d0 ; Patch
; Install interrupts
lea crash_handler-bloc(a0),a2 ; Install crash handler
moveq #7-1,d0
lea ($40000+$8+$4),a3
loop_handler: move.l a2,(a3)+ ; Install new one
dbra d0,loop_handler
; Intercept the jsr 0 / jmp 0 bugs : execs instruction FF00 ! => Calls crash handler
; But it won't interfere with Reset since it uses the upper byte of the address
; It freezes the calc if you are in Grah mode !
; Sur ROM 2.05, a l'adresse 92p, $422CAE, il y a move.w $00,d0 !!!
; Mais a quoi ca peut bien servir !
; st.b ($40000)
lea newER_throw-bloc(a0),a2 ;l'adresse où sera ER_throw
lea OldER_throw+2(Pc),a3
move.l -12(a6),(a3) ;$28
move.l a2,-12(a6) ;$28
lea new1111-bloc(a0),a2 ;l'adresse où sera LineEmulator 1111
; lea Old1111+2(Pc),a3
; move.l -8(a6),(a3) ;$2C
move.l a2,-8(a6) ;$2C
lea oldint6+2(Pc),a2
move.l ($64+5*4).w,(a2)
lea newint6-bloc(a0),a1
move.l a1,$40064+5*4
; Gestion des RAMCALLS
lea RAM_TABLE(pc),a3
lea Calc-bloc(a0),a2 ;l'adresse où sera CALC
move.l a2,(a3) ;place l'adresse de CALC
lea RetVal-bloc(a0),a2 ; L'adresse ou sera RetVal
move.l a2,($F*4)(a3) ; Sauver
lea ($15*4)(a3),a1
lea kernel::idle-bloc(a0),a2
move.l a2,(a1)+
lea kernel::exec-bloc(a0),a2
move.l a2,(a1)+
lea kernel::Ptr2Hd-bloc(a0),a2
move.l a2,(a1)+
lea kernel::Hd2Sym-bloc(a0),a2
move.l a2,(a1)+
lea kernel::LibsBegin-bloc(a0),a2
move.l a2,(a1)+
lea kernel::LibsEnd-bloc(a0),a2
move.l a2,(a1)+
lea kernel::LibsCall-bloc(a0),a2
move.l a2,(a1)+
lea kernel::LibsPtr-bloc(a0),a2
move.l a2,(a1)+
lea kernel::LibsExec-bloc(a0),a2
move.l a2,(a1)+
lea kernel::HdKeep-bloc(a0),a2
move.l a2,(a1)+
; Gestion valeur 89/92p du kernel
; Emplacement de la ligne
move.w #(LCD_MEM+30*(100-7)),d1 ; Valeur 89
move.w #%0111111,d2 ; Key Mask pour ESC
clr.w d3 ; Key Bit pour ESC
move.b Calc(Pc),d0
beq.s s89
move.w #LCD_MEM+30*(128-7),d1 ; Valeur 92
move.w #%1011111111,d2 ; Key Mask pour ESC
moveq #6,d3 ; Key Bit pour ESC
s89
add.b d0,d0 ; x2 Pour offset
lea ExtraRamCalc+3(Pc),a2 ; Sauve l'offset de l'extraram call
move.b d0,(a2)
lea blackline+2(Pc),a2 ; Sauve l'adresse de la ligne noire
move.w d1,(a2)
lea int6msk+2(Pc),a2 ; Sauve le masque
move.w d2,(a2)
lea int6key+2(Pc),a2 ; Sauve le champ de bit
move.w d3,(a2)
; Gestion valeur hw1/hw2 du kernel
; Valeur originelle du timer $17
moveq #$FFFFFFB2,d1 ; Valeur Hw1
move.b Hw(Pc),d0
subq.b #1,d0
ble.s hw1
moveq #$FFFFFFCC,d1 ; Valeur Hw2
hw1 lea hwtimer+3(Pc),a2 ; Sauve la valeur
move.b d1,(a2)
; Relocation du trap #0
lea NewTrap0-bloc(a0),a1
lea Trap0Adr+2(Pc),a2
move.l a1,(a2)
lea ResetTrap0-bloc(a0),a1
lea resetTrap0Adr+2(Pc),a2
move.l a1,(a2)
; Ecriture valeur
move.l a0,(a6)+ ;début du bloc contient exec
lea reloc-bloc(a0),a1
move.l a1,(a6)+
lea reloc2-bloc(a0),a1
move.l a1,(a6)+
lea unreloc-bloc(a0),a1
move.l a1,(a6)+
lea unreloc2-bloc(a0),a1
move.l a1,(a6)+
lea bloc(pc),a1 ;copie le bloc en RAM
move.w #(blocfin-bloc)/2-1,d0
copy: move.w (a1)+,(a0)+
dbra d0,copy
; The KERNEL is installed
; 8 Finish all !
lea -1000(a7),a7
move.l a7,a4
move.w #(blocfin-bloc),-(a7)
pea success(pc)
pea (a4)
ROM_THROW sprintf
lea (4+4+2+1000)(a7),a7
move.l a4,a0 ; Vicieux ;)
; In: a0-> String to print
exit:
ifne 0
pea (1).w
pea (a0)
pea title(pc)
ROM_CALL DlgMessage ; Can be called even if UniOs is installed !
lea 12(a7),a7
endif
ifeq 0
pea (a0)
ROM_CALL ST_helpMsg
addq.l #4,a7
endif
; Install new auto-ints and ev_hook
moveq #7-1,d0
lea ($40064),a1
lea ($400E0-$40064)(a1),a2
loop_autoint: move.l (a1)+,(a2)+ ; Save old handler
dbra d0,loop_autoint
ROM_PTR EV_hook
move.l (a0),(a2)+ ; save EV_hook
; Search for outdated libs
ifne 0
move.w #2,-(a7) ; Parcourt de l'ensemble de la VAT
clr.l -(a7)
ROM_CALL SymFindFirst
addq.l #6,a7
loop lea mmauvaise(Pc),a1
move.w SYM_ENTRY.hVal(a0),-(a7) ; Push handle
move.l (a0)+,(a1)+
move.l (a0)+,(a1)+ ; Copy lib name
ROM_CALL HeapDeref
addq.l #2,a7
moveq #0,d0
move.w (a0)+,d0
cmp.b #$F3,-1(a0,d0.l)
bne.s next
cmp.l #'68kL',4(a0)
bne.s next
tst.b VERSION_OFFSET(a0) ; Updated Libs
bne.s next
move.l #1*65536+4,-(a7)
pea mwrong(Pc)
pea title(pc)
ROM_CALL DlgMessage
lea 12(a7),a7
cmp.w #13,d0
bne.s stop_lib
next ROM_CALL SymFindNext
move.l a0,d0
bne.s loop
stop_lib
endif
; Quit program
movem.l (a7)+,d3-d7/a2-a6
dont_install
rts
valeursRAMti89 dc.l 160,100,$200000,20,338,344,337,340,345,342,$4000,2000,$2000
valeursRAMti92 dc.l 240,128,$400000,30,337,340,338,344,342,345,$2000,3840,$4000
bloc:
include Exec.asm
include Ints.asm
include ext.asm
blocfin:
; Strings
title dc.b "PreOS v0.55.13" ; Title
ifd hw2tsr
dc.b "-HW2TSR" ; Hw2Tsr Title
endif
ifnd ShiftOnKernel
dc.b "-tictex"
endif
dc.b 0
success dc.b "Success ! (%u bytes)",0
already dc.b "Load new auto-ints & ev_hook",0
ifnd hw2tsr
hw2patch dc.b "Install HW2Patch first",0
endif
memory dc.b "Not enough memory",0
dc.b 0,"main"
main_str_end dc.b 0
end