Browse Source

Create new CVS module for TIGCC (start with TIGCCLIB).

git-svn-id: file:///var/svn/tigccpp/branches/TIGCC@6 9552661e-59e3-4036-b4f2-dbe53926924f
kevinkofler 19 years ago
commit
69be87fd5c
100 changed files with 4602 additions and 0 deletions
  1. 29 0
      tigcc/archive/License.txt
  2. 6 0
      tigcc/archive/addbf.s
  3. 24 0
      tigcc/archive/ashldi.s
  4. 31 0
      tigcc/archive/ashrdi.s
  5. 62 0
      tigcc/archive/assert.s
  6. 109 0
      tigcc/archive/atexit.s
  7. 44 0
      tigcc/archive/atof.s
  8. 12 0
      tigcc/archive/atoi.c
  9. 59 0
      tigcc/archive/atoi.s
  10. 13 0
      tigcc/archive/atol.c
  11. 65 0
      tigcc/archive/atol.s
  12. 19 0
      tigcc/archive/bc.s
  13. 13 0
      tigcc/archive/bcopy.s
  14. 19 0
      tigcc/archive/bsearch.c
  15. 52 0
      tigcc/archive/bsearch.s
  16. 12 0
      tigcc/archive/bzero.s
  17. 23 0
      tigcc/archive/calloc.s
  18. 10 0
      tigcc/archive/calloc_throw.s
  19. 25 0
      tigcc/archive/cbprintf.s
  20. 564 0
      tigcc/archive/cbscanf.s
  21. 12 0
      tigcc/archive/clrscr.s
  22. 12 0
      tigcc/archive/cmpbf.s
  23. 10 0
      tigcc/archive/contrastdn.s
  24. 10 0
      tigcc/archive/contrastup.s
  25. 6 0
      tigcc/archive/divbf.s
  26. 37 0
      tigcc/archive/divdi.s
  27. 11 0
      tigcc/archive/diventry.s
  28. 6 0
      tigcc/archive/divsi.s
  29. 71 0
      tigcc/archive/dll.c
  30. 245 0
      tigcc/archive/dll.s
  31. 5 0
      tigcc/archive/dummyhandler.s
  32. 6 0
      tigcc/archive/enter_ghost_space.s
  33. 8 0
      tigcc/archive/enter_ghost_space_1.s
  34. 87 0
      tigcc/archive/enter_ghost_space_2.s
  35. 13 0
      tigcc/archive/exit.s
  36. 32 0
      tigcc/archive/fargo.tpr
  37. 16 0
      tigcc/archive/fclose.c
  38. 49 0
      tigcc/archive/fclose.s
  39. 18 0
      tigcc/archive/fgetc.c
  40. 71 0
      tigcc/archive/fgetc.s
  41. 54 0
      tigcc/archive/fgetchar.s
  42. 59 0
      tigcc/archive/fgetchrc.s
  43. 14 0
      tigcc/archive/fgets.c
  44. 52 0
      tigcc/archive/fgets.s
  45. 33 0
      tigcc/archive/findprogramvar.c
  46. 58 0
      tigcc/archive/findprogramvar.s
  47. 7 0
      tigcc/archive/fixbf.s
  48. 6 0
      tigcc/archive/floatbf.s
  49. 85 0
      tigcc/archive/fopen.c
  50. 242 0
      tigcc/archive/fopen.s
  51. 17 0
      tigcc/archive/fpcall.s
  52. 11 0
      tigcc/archive/fpentry.s
  53. 17 0
      tigcc/archive/fprintf.s
  54. 33 0
      tigcc/archive/fputc.c
  55. 116 0
      tigcc/archive/fputc.s
  56. 70 0
      tigcc/archive/fputchar.s
  57. 15 0
      tigcc/archive/fputs.s
  58. 17 0
      tigcc/archive/fread.c
  59. 45 0
      tigcc/archive/fread.s
  60. 25 0
      tigcc/archive/freetimer.s
  61. 22 0
      tigcc/archive/fscanf.s
  62. 17 0
      tigcc/archive/fseek.c
  63. 74 0
      tigcc/archive/fseek.s
  64. 7 0
      tigcc/archive/fsetbufsize.c
  65. 19 0
      tigcc/archive/fsetbufsize.s
  66. 7 0
      tigcc/archive/ftell.c
  67. 34 0
      tigcc/archive/ftell.s
  68. 14 0
      tigcc/archive/fwrite.c
  69. 48 0
      tigcc/archive/fwrite.s
  70. 54 0
      tigcc/archive/getappid.s
  71. 72 0
      tigcc/archive/gets.s
  72. 76 0
      tigcc/archive/getsn.s
  73. 660 0
      tigcc/archive/gray.s
  74. 10 0
      tigcc/archive/gray_throw.s
  75. 1 0
      tigcc/archive/grayversion.c
  76. 8 0
      tigcc/archive/grayversion.s
  77. 22 0
      tigcc/archive/homestore.s
  78. 25 0
      tigcc/archive/homestorepair.c
  79. 83 0
      tigcc/archive/homestorepair.s
  80. 15 0
      tigcc/archive/hrealloc_throw.s
  81. 49 0
      tigcc/archive/hw_version.s
  82. 5 0
      tigcc/archive/isextalnum.s
  83. 5 0
      tigcc/archive/isextpunct.s
  84. 7 0
      tigcc/archive/kbd_queue.s
  85. 15 0
      tigcc/archive/loaddll_throw.s
  86. 24 0
      tigcc/archive/lshrdi.s
  87. 15 0
      tigcc/archive/malloc_throw.s
  88. 30 0
      tigcc/archive/moddi.s
  89. 6 0
      tigcc/archive/modsi.s
  90. 6 0
      tigcc/archive/mulbf.s
  91. 58 0
      tigcc/archive/muldi.s
  92. 17 0
      tigcc/archive/mulsi.s
  93. 6 0
      tigcc/archive/negbf.s
  94. 8 0
      tigcc/archive/nocallback.s
  95. 22 0
      tigcc/archive/prgstart.s
  96. 17 0
      tigcc/archive/printf.s
  97. 43 0
      tigcc/archive/push_longint.s
  98. 50 0
      tigcc/archive/push_longlongint.s
  99. 43 0
      tigcc/archive/push_shortint.s
  100. 16 0
      tigcc/archive/pushfifonode.c

+ 29 - 0
tigcc/archive/License.txt

@@ -0,0 +1,29 @@
+TIGCC Library Routines
+Copyright (C) 2000-2003 Zeljko Juric,
+                        Thomas Nussbaumer,
+                        Kevin Kofler, and
+                        Sebastian Reichelt
+
+This file is part of TIGCC.
+
+TIGCC is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+In addition to the permissions in the GNU General Public License, the
+TIGCC Team gives you unlimited permission to link the compiled
+versions of these files with other programs, and to distribute
+those programs without any restriction coming from the use of this
+file.  (The General Public License restrictions do apply in other
+respects; for example, they cover modification of the files, and
+distribution when not linked into another program.)
+
+These files are distributed in the hope that they will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, write to the Free Software
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

+ 6 - 0
tigcc/archive/addbf.s

@@ -0,0 +1,6 @@
+	.xdef __addbf3
+
+.text
+__addbf3:
+	moveq.l #0,%d0
+	jra __fp_entry

+ 24 - 0
tigcc/archive/ashldi.s

@@ -0,0 +1,24 @@
+|ashldi3 routine copyright (C) 2002, Kevin Kofler
+
+	.xdef __ashldi3
+
+.text
+__ashldi3:
+	tst.w 12(%a7)
+	bne.s .L__ashldi3_return0
+	move.l 4(%a7),%d0
+	move.l 8(%a7),%d1
+	move.w 14(%a7),%d2
+	beq.s .L__ashldi3_returnn
+	subq.w #1,%d2
+.L__ashldi3_loop:
+	add.l %d1,%d1
+	addx.l %d0,%d0
+	dbra.w %d2,.L__ashldi3_loop
+.L__ashldi3_returnn:
+	rts
+
+.L__ashldi3_return0:
+	moveq.l #0,%d0
+	moveq.l #0,%d1
+	rts

+ 31 - 0
tigcc/archive/ashrdi.s

@@ -0,0 +1,31 @@
+|ashrdi3 routine copyright (C) 2002, Kevin Kofler
+
+	.xdef __ashrdi3
+
+.text
+__ashrdi3:
+	tst.w 12(%a7)
+	bne.s .L__ashrdi3_return0
+	move.l 4(%a7),%d0
+	move.l 8(%a7),%d1
+	move.w 14(%a7),%d2
+	beq.s .L__ashrdi3_returnn
+	subq.w #1,%d2
+.L__ashrdi3_loop:
+	asr.l #1,%d0
+	roxr.l #1,%d1
+	dbra.w %d2,.L__ashrdi3_loop
+.L__ashrdi3_returnn:
+	rts
+
+.L__ashrdi3_return0:
+	tst.b 4(%a7)
+	blt.s .L__ashrdi3_return_neg1
+	moveq.l #0,%d0
+	moveq.l #0,%d1
+	rts
+
+.L__ashrdi3_return_neg1:
+	moveq.l #-1,%d0
+	moveq.l #-1,%d1
+	rts

+ 62 - 0
tigcc/archive/assert.s

@@ -0,0 +1,62 @@
+	.xdef __assertion_failed
+
+| This file requires the startup exit support.
+	.xdef __ref_all___save_all_registers
+
+.text
+__assertion_failed:
+	link.w %a6,#-1044
+	move.l 0xC8,%a2
+	move.w 16(%a6),(%sp)
+	move.l 12(%a6),-(%sp)
+	move.l 8(%a6),-(%sp)
+	pea .L__assert_fmt
+	lea -1000(%a6),%a4
+	move.l %a4,-(%sp)
+	move.l 332(%a2),%a0 /* sprintf */
+	jsr (%a0)
+	move.l 188(%a2),%a0 /* ScrRect */
+	clr.l %d0
+	move.b 2(%a0),%d0
+	swap %d0
+	move.b 3(%a0),%d0
+	add.l #0xFFF5FFF1,%d0
+	move.l %d0,(%sp)
+	move.l #0xA000A,-(%sp)
+	move.l 176(%a2),%a0 /* MakeWinRect */
+	jsr (%a0)
+	pea .L__assert_ttl
+	move.w #0x1058,-(%sp)
+	move.l %a0,-(%sp)
+	pea -1042(%a6)
+	move.l 120(%a2),%a0 /* WinOpen */
+	jsr (%a0)
+	move.l 4(%a2),%a0
+	jsr (%a0)
+	clr.w 4(%sp)
+	move.l 76(%a2),%a0 /* WinFont */
+	jsr (%a0)
+	move.l %a4,4(%sp)
+	move.l 148(%a2),%a0 /* WinStr */
+	jsr (%a0)
+	move.l #0x10008,4(%sp)
+	move.l 212(%a2),%a0 /* DrawStaticButton */
+	jsr (%a0)
+.L__assert_wkey:
+	move.l 324(%a2),%a0 /* ngetchx */
+	jsr (%a0)
+	cmp.w  #13,%d0
+	jbne .L__assert_wkey
+	move.l 44(%a2),%a0 /* WinClose */
+	jsr (%a0)
+	movea.l __save__sp__:l,%a7
+	rts
+.L__assert_ttl:
+	.ascii "ASSERTION FAILED"
+	.word 0
+.L__assert_fmt:
+	.byte 10
+	.ascii " Condition: %s"
+	.byte 10,10
+	.ascii " File: %s  Line: %d"
+	.word 0

+ 109 - 0
tigcc/archive/atexit.s

@@ -0,0 +1,109 @@
+|atexit function copyright (C) 2002, Kevin Kofler
+|requires new exit support (__save__sp__)
+|Many thanks to Patrick Pélissier and Stephan Effelsberg for ideas on how to
+|implement this. Stephan Effelsberg's C implementation inspired this mostly,
+|but I have changed it so that exit and atexit will not be included if not
+|used. There is only a small 20-byte exit support needed.
+
+	.xdef atexit
+
+| This file requires the startup exit support.
+	.xdef __ref_all___save_all_registers_main
+
+.text
+
+	.equ __malloc,0xa2 /* HeapAllocPtr */
+	.equ __free,0xa3   /* HeapFreePtr */
+	.equ __num_regs,10 |number of registers saved by the exit support
+
+atexit:
+|find the return address:
+	movea.l __save__sp__:l,%a0 |stack pointer before restoring the registers
+	                           |(NOT PC-relative because of programs >32 KB)
+|The return address is now at (a0).
+
+|check if the return address is .L__atexit__new__return
+	cmpi.l #.L__atexit__new__return:l,(%a0)
+	beq.s .L__atexit__return__address__ok |if it is, skip ahead
+|Else:
+|- move the current return address to .L__atexit__return+2
+	move.l (%a0),.L__atexit__return+2
+|- change the return address to .L__atexit__new__return
+	move.l #.L__atexit__new__return:l,(%a0)
+	clr.l .L__atexit__num__funcs |initialize the number of atexit functions to 0
+
+|allocate a handle for the functions
+	pea.l 4:w
+	movea.l 0xc8,%a0
+	move.l (__malloc*4,%a0),%a0
+	jsr (%a0) |a0=malloc(4);
+	addq.l #4,%a7
+	bra.s .L__atexit__handle__allocated
+
+.L__atexit__return__address__ok:
+|reallocate the handle for the functions
+	move.l (.L__atexit__num__funcs,%PC),%d0
+	lsl.l #2,%d0
+	addq.l #4,%d0
+	move.l (.L__atexit__ptr__funcs,%PC),%a0
+	jbsr realloc |a0=realloc(.L__atexit__ptr__funcs,.L__atexit__num__funcs*4+4);
+
+.L__atexit__handle__allocated:
+|If a0 is NULL, there was not enough memory, so we return an error code.
+	moveq #0,%d0
+	cmpa.l %d0,%a0 |if (!a0)
+	seq.b %d0
+	beq.s .L__atexit__rts |return 255;
+
+	move.l %a0,.L__atexit__ptr__funcs |save a0 to .L__atexit__ptr__funcs
+|Now we store the function given as an argument into the allocated memory.
+	move.l (.L__atexit__num__funcs,%PC),%d1
+	lsl.l #2,%d1
+	move.l (4,%a7),(0,%a0,%d1:l) |.L__atexit__ptr__funcs[.L__atexit__num__funcs]=4(a7);
+
+|And there is 1 more atexit function now:
+	addq.l #1,.L__atexit__num__funcs
+
+.L__atexit__rts:
+	rts
+
+|This will be executed when the _main function or the exit function tries to
+|return:
+.L__atexit__new__return:
+	move.l (.L__atexit__num__funcs,%PC),%d0 |if there are no functions to call, return
+	beq.s .L__atexit__no__funcs             |immediately
+
+|	movem.l %a2/%a5/%d3,-(%a7)
+|no need to save and restore the registers, the exit support will do it for us
+	movea.l 0xc8,%a5
+	movea.l (.L__atexit__ptr__funcs,%PC),%a2
+	move.l %d0,%d3 |save d0 to d3
+	lsl.l #2,%d0 |point a2 to the address of the last function + 4
+	add.l %d0,%a2 |that is, .L__atexit__ptr__funcs[.L__atexit__num__funcs]
+
+	subq.l #1,%d3 |subtract 1 from the number of functions for the dbra loop
+
+|call all atexit functions now
+.L__atexit__loop:
+	movea.l -(%a2),%a0
+	jsr (%a0)
+	dbra.w %d3,.L__atexit__loop
+
+|a2 now points to the beginning of the allocated memory for the pointers
+|free this memory
+	pea.l (%a2)
+	move.l (__free*4,%a5),%a0
+	jsr (%a0) |free(.L__atexit__ptr__funcs);
+	addq.l #4,%a7
+
+|	movem.l (%a7)+,%a2/%a5/%d3
+|no need to save and restore the registers, the exit support will do it for us
+.L__atexit__no__funcs:
+
+|This will return to the actual return address (which will be patched in
+|instead of the 0 by the first call to atexit).
+.L__atexit__return: jmp.l 0:l
+
+|data:
+.L__atexit__ptr__funcs: .long 0 |pointer to the atexit functions
+.L__atexit__num__funcs: .long 0 |number of atexit functions

+ 44 - 0
tigcc/archive/atof.s

@@ -0,0 +1,44 @@
+	.xdef atof
+
+.text
+atof:
+	link.w %a6,#-80
+	movem.l %d3-%d7/%a2-%a5,-(%sp)
+	move.l 0xC8,%a4
+	move.l 1060(%a4),%a3 /* top_estack */
+	move.l (%a3),%d4
+	pea -80(%a6)
+	move.l 1360(%a4),%a0 /* ER_catch */
+	jsr (%a0)
+	tst.w %d0
+	jbeq .L__atof_1
+	move.l #0x7FFFAA00,%d0
+	clr.l %d1
+	clr.w %d2
+	jbra .L__atof_3
+.L__atof_1:
+	move.l 8(%a6),(%sp)
+	move.l 3880(%a4),%a0 /* push_parse_text */
+	jsr (%a0)
+	move.l (%a3),%a0
+	move.b (%a0),%d5
+	cmpi.b #0x7A,%d5
+	bne.s .L__atof_2
+	subq #1,%a0
+.L__atof_2:
+	move.l %a0,(%sp)
+	move.l 3044(%a4),%a0 /* estack_number_to_Float */
+	jsr (%a0)
+	move.l %d4,(%a3)
+	move.l 1364(%a4),%a0 /* ER_success */
+	jsr (%a0)
+	move.l (%a6,-10),%d0
+	move.l (%a6,-6),%d1
+	move.w (%a6,-2),%d2
+	cmpi.b #0x7A,%d5
+	bne.s .L__atof_3
+	bset #31,%d0
+.L__atof_3:
+	movem.l -116(%a6),%d3-%d7/%a2-%a5
+	unlk %a6
+	rts

+ 12 - 0
tigcc/archive/atoi.c

@@ -0,0 +1,12 @@
+#include <stdlib.h>
+#include <ctype.h>
+
+__ATTR_LIB_C__ short atoi(const char *s)
+{
+  unsigned short c,value=0,neg=0;
+  while(*s==' ') ++s;
+  if(*s=='-'||*(const unsigned char*)s==0xAD) ++s,neg=-1;
+  else if(*s=='+') ++s;
+  while(isdigit(c=*(const unsigned char*)s++)) value=10*value+c-'0';
+  return neg?-value:value;
+}

+ 59 - 0
tigcc/archive/atoi.s

@@ -0,0 +1,59 @@
+	.file	"atoi.c"
+#NO_APP
+	.text
+tigcc_compiled.:
+#APP
+	.set _A_LINE,0xA000
+#NO_APP
+	.text
+	.even
+	.globl	atoi
+atoi:
+	move.l %d3,-(%sp)
+	clr.w %d2
+	clr.w %d3
+	jbra .L2
+	.even
+.L5:
+	addq.l #1,%a0
+.L2:
+	move.b (%a0),%d0
+	cmp.b #32,%d0
+	jbeq .L5
+	cmp.b #45,%d0
+	jbeq .L7
+	cmp.b #-83,%d0
+	jbne .L6
+.L7:
+	addq.l #1,%a0
+	moveq.l #-1,%d3
+	jbra .L10
+	.even
+.L6:
+	cmp.b #43,%d0
+	jbne .L10
+	addq.l #1,%a0
+	jbra .L10
+	.even
+.L13:
+	muls.w #10,%d2
+	add.w %d1,%d2
+	add.w #-48,%d2
+.L10:
+	clr.w %d1
+	move.b (%a0)+,%d1
+	move.w %d1,%d0
+	add.w #-48,%d0
+	cmp.w #9,%d0
+	sls %d0
+	ext.w %d0
+	neg.w %d0
+	jbne .L13
+	move.w %d2,%d0
+	neg.w %d0
+	tst.w %d3
+	jbne .L15
+	move.w %d2,%d0
+.L15:
+	move.l (%sp)+,%d3
+	rts

+ 13 - 0
tigcc/archive/atol.c

@@ -0,0 +1,13 @@
+#include <stdlib.h>
+#include <ctype.h>
+
+__ATTR_LIB_C__ long atol(const char *s)
+{
+  unsigned short c,neg=0;
+  long value=0;
+  while(*s==' ') ++s;
+  if(*s=='-'||*(const unsigned char*)s==0xAD) ++s,neg=-1;
+  else if(*s=='+') ++s;
+  while(isdigit(c=*(const unsigned char*)s++)) value=(value<<3)+(value<<1)+c-'0';
+  return neg?-value:value;
+}

+ 65 - 0
tigcc/archive/atol.s

@@ -0,0 +1,65 @@
+	.file	"atol.c"
+#NO_APP
+	.text
+tigcc_compiled.:
+#APP
+	.set _A_LINE,0xA000
+#NO_APP
+	.text
+	.even
+	.globl	atol
+atol:
+	move.l %d3,-(%sp)
+	move.l %a0,%a1
+	clr.w %d3
+	moveq.l #0,%d2
+	jbra .L2
+	.even
+.L5:
+	addq.l #1,%a1
+.L2:
+	move.b (%a1),%d0
+	cmp.b #32,%d0
+	jbeq .L5
+	cmp.b #45,%d0
+	jbeq .L7
+	cmp.b #-83,%d0
+	jbne .L6
+.L7:
+	addq.l #1,%a1
+	moveq.l #-1,%d3
+	jbra .L10
+	.even
+.L6:
+	cmp.b #43,%d0
+	jbne .L10
+	addq.l #1,%a1
+	jbra .L10
+	.even
+.L13:
+	move.l %d2,%d0
+	add.l %d0,%d0
+	lsl.l #3,%d2
+	move.l %d2,%a0
+	add.l %d0,%a0
+	clr.l %d0
+	move.b %d1,%d0
+	lea -48(%a0,%d0.l),%a0
+	move.l %a0,%d2
+.L10:
+	clr.w %d1
+	move.b (%a1)+,%d1
+	move.w %d1,%d0
+	add.w #-48,%d0
+	cmp.w #9,%d0
+	sls %d0
+	ext.w %d0
+	neg.w %d0
+	jbne .L13
+	move.l %d2,%d0
+	tst.w %d3
+	jbeq .L14
+	neg.l %d0
+.L14:
+	move.l (%sp)+,%d3
+	rts

+ 19 - 0
tigcc/archive/bc.s

@@ -0,0 +1,19 @@
+	.xdef __BC
+
+.text
+__BC:
+	link %a6,#-10
+	move.l (%a6,26),-(%sp)
+	move.l (%a6,22),-(%sp)
+	move.l (%a6,18),-(%sp)
+	move.l (%a6,14),-(%sp)
+	move.l (%a6,10),-(%sp)
+	move.w (%a6,8),%d0
+	move.l 0xC8,%a0
+	move.l (%a0,%d0.w),%a0
+	jsr (%a0)
+	move.l (%a6,-10),%d0
+	move.l (%a6,-6),%d1
+	move.w (%a6,-2),%d2
+	unlk %a6
+	rts

+ 13 - 0
tigcc/archive/bcopy.s

@@ -0,0 +1,13 @@
+	.xdef bcopy
+
+.text
+bcopy:
+	move.w (12,%sp),-(%sp)
+	clr.w -(%sp)
+	move.l (8,%sp),-(%sp)
+	move.l (16,%sp),-(%sp)
+	movea.l 0xC8,%a0
+	movea.l (%a0,0x26A*4),%a0
+	jsr (%a0) /* memcpy */
+	lea (%sp,12),%sp
+	rts

+ 19 - 0
tigcc/archive/bsearch.c

@@ -0,0 +1,19 @@
+#include <stdlib.h>
+
+// Do not use register a5; callback function might need it.
+register long __tbl asm ("a5");
+
+__ATTR_LIB_C__ void *bsearch(const void *key, const void *bptr, short n, short w, compare_t cmp_func)
+{
+  unsigned short left=0,right=n-1,index;
+  short rcmp;
+  void *rptr;
+  do
+    {
+      index=(left+right)>>1;
+      if((rcmp=cmp_func(key,rptr=(char*)bptr+(long)index*(unsigned short)w))>0) left=index+1;
+      else if(rcmp<0) right=index-1;
+      else return rptr;
+    } while(left<=right);
+  return 0;
+}

+ 52 - 0
tigcc/archive/bsearch.s

@@ -0,0 +1,52 @@
+	.file	"bsearch.c"
+#NO_APP
+	.text
+tigcc_compiled.:
+#APP
+	.set _A_LINE,0xA000
+#NO_APP
+	.text
+	.even
+	.globl	bsearch
+bsearch:
+	movm.l #0x1f38,-(%sp)
+	move.l %a0,%a4
+	move.l %a1,%a3
+	move.w %d1,%d7
+	clr.w %d6
+	move.w %d0,%d4
+	subq.w #1,%d4
+.L2:
+	move.w %d6,%d3
+	add.w %d4,%d3
+	lsr.w #1,%d3
+	move.w %d3,%d0
+	mulu.w %d7,%d0
+	move.l %a3,%d5
+	add.l %d0,%d5
+	move.l %d5,-(%sp)
+	move.l %a4,-(%sp)
+	jbsr (%a2)
+	addq.l #8,%sp
+	tst.w %d0
+	jble .L5
+	move.w %d3,%d6
+	addq.w #1,%d6
+	jbra .L4
+	.even
+.L5:
+	move.w %d3,%d4
+	subq.w #1,%d4
+	tst.w %d0
+	jblt .L4
+	move.l %d5,%d0
+	jbra .L1
+	.even
+.L4:
+	cmp.w %d6,%d4
+	jbcc .L2
+	moveq.l #0,%d0
+.L1:
+	move.l %d0,%a0
+	movm.l (%sp)+,#0x1cf8
+	rts

+ 12 - 0
tigcc/archive/bzero.s

@@ -0,0 +1,12 @@
+	.xdef bzero
+
+.text
+bzero:
+	move.w (8,%sp),-(%sp)
+	clr.l -(%sp)
+	move.l (10,%sp),-(%sp)
+	movea.l 0xC8,%a0
+	movea.l (%a0,0x27C*4),%a0	   
+	jsr (%a0) /* memset */
+	lea (%sp,10),%sp
+	rts

+ 23 - 0
tigcc/archive/calloc.s

@@ -0,0 +1,23 @@
+	.xdef calloc
+
+.text
+calloc:
+	mulu.w %d1,%d0
+	move.l %d0,-(%sp)
+	move.l 0xC8,%a0
+	move.l 648(%a0),%a0 /* HeapAllocPtr */
+	jsr (%a0)
+	move.l %a0,%d0
+	jbeq .L__calloc_1
+	clr.w -(%sp)
+	move.l %a0,-(%sp)
+	move.l 0xC8,%a0
+	move.l 2544(%a0),%a0 /* memset */
+	jsr (%a0)
+	addq.l #6,%sp
+	jbra .L__calloc_2
+.L__calloc_1:
+	suba.l %a0,%a0
+.L__calloc_2:
+	addq.l #4,%sp
+	rts

+ 10 - 0
tigcc/archive/calloc_throw.s

@@ -0,0 +1,10 @@
+	.xdef calloc_throw
+
+.text
+calloc_throw:
+	jbsr calloc
+	move.l %a0,%d0
+	jbne .L__finished
+	.word 0xA000+670
+.L__finished:
+	rts

+ 25 - 0
tigcc/archive/cbprintf.s

@@ -0,0 +1,25 @@
+|cbprintf() (non-virtual vcbprintf()) implementation for TIGCCLIB
+|Copyright (C) Kevin Kofler, 2003
+
+| Warning: This routine has the attribute __ATTR_TIOS__!
+
+.xdef cbprintf
+cbprintf:
+|Copy the arguments for vcbprintf(). We have to copy them because of the stack
+|parameter convention of AMS. Register parameters wouldn't need a copy.
+	pea.l 16(%a7) | arglist: do NOT copy this one, pass a pointer to it
+	move.l 16(%a7),-(%a7) | copy format
+	move.l 16(%a7),-(%a7) | copy param
+	move.l 16(%a7),-(%a7) | copy callback
+
+|Now call vcbprintf using the usual hack.
+|Copied from Zeljko Juric's printf.
+	movea.l 0xC8,%a0
+	movea.l (%a0,0x14C),%a0 /* vcbprintf */
+	lea (%a0,32),%a0
+	movea.w (%a0),%a1
+	jsr (%a0.l,%a1)
+
+|Pop the arguments from the stack and return.
+	lea.l 16(%a7),%a7
+	rts

+ 564 - 0
tigcc/archive/cbscanf.s

@@ -0,0 +1,564 @@
+|*cbscanf() implementation for TIGCCLIB
+|WARNING: This implementation might accept broken format strings (for size
+|         reasons). For example: "%1h2d" == "%h12d".
+|Copyright (C) Kevin Kofler, 2002-2003
+
+/*Prototypes:
+  typedef CALLBACK short (*__cbscanf_get_Callback_t) (void *param);
+  typedef CALLBACK void (*__cbscanf_unget_Callback_t) (short c, void *param);
+  short cbscanf(register __cbscanf_get_Callback_t getfun asm("a0"),
+                register __cbscanf_unget_Callback_t ungetfun asm("a1"),
+                register void *param asm("a2"),
+                register const char *format asm("a3"), ...);
+  short vcbscanf(register __cbscanf_get_Callback_t getfun asm("a0"),
+                 register __cbscanf_unget_Callback_t ungetfun asm("a1"),
+                 register void *param asm("a2"),
+                 register const char *format asm("a3"),
+                 register va_list arglist asm("a4"));
+  */
+
+.text
+.xdef vcbscanf
+vcbscanf:
+movem.l %d3-%d7/%a2-%a4/%a6,-(%a7)
+bra.s __vcbscanf_entry_point
+
+.xdef cbscanf
+cbscanf:
+movem.l %d3-%d7/%a2-%a4/%a6,-(%a7)
+lea.l 4+9*4(%a7),%a4
+__vcbscanf_entry_point:
+clr.w %d4 |number of bytes read from input
+clr.w %d0 |result (number of tokens read in)
+__cbscanf_next:
+move.b (%a3)+,%d1 |current format character
+beq.s __cbscanf_return
+cmp.b #'%',%d1
+beq __cbscanf_conversion
+cmp.b #32,%d1
+beq.s __cbscanf_whitespace
+cmp.b #13,%d1
+bhi.s 0f
+cmp.b #9,%d1
+bcc.s __cbscanf_whitespace
+0:
+__cbscanf_literal:
+|literal character
+bsr.s __cbscanf_getc
+cmp.w #-1,%d2
+beq.s __cbscanf_return
+cmp.b %d1,%d2
+beq.s __cbscanf_next
+__cbscanf_return:
+|return EOF if EOF occured with no conversions done
+tst.w %d0
+bne.s 45f
+addq.w #1,%d2
+bne.s 45f
+moveq.l #-1,%d0
+45:
+movem.l (%a7)+,%d3-%d7/%a2-%a4/%a6
+rts
+
+__cbscanf_getc:
+movem.l %d0-%d1/%a0-%a1,-(%a7)
+pea.l (%a2)
+jsr (%a0)
+addq.l #4,%a7
+move.w %d0,%d2
+addq.w #1,%d4
+movem.l (%a7)+,%d0-%d1/%a0-%a1
+rts
+
+__cbscanf_ungetc:
+cmp.w #-1,%d2 |don't unget EOF
+beq.s 46f
+movem.l %d0-%d2/%a0-%a1,-(%a7)
+pea.l (%a2)
+move.w %d2,-(%a7)
+jsr (%a1)
+addq.l #6,%a7
+movem.l (%a7)+,%d0-%d2/%a0-%a1
+46:
+subq.w #1,%d4
+rts
+
+__cbscanf_whitespace:
+addq.l #1,%a3
+move.b (%a3),%d1
+cmp.b #32,%d1
+beq.s __cbscanf_whitespace
+cmp.b #13,%d1
+bhi.s 1f
+cmp.b #9,%d1
+bcc.s __cbscanf_whitespace
+1:
+clr.w %d1
+__cbscanf_whitespace2:
+addq.w #1,%d1 |count whitespace chars
+bsr.s __cbscanf_getc
+cmp.b #32,%d2
+beq.s __cbscanf_whitespace2
+cmp.b #13,%d2
+bhi.s 2f
+cmp.b #9,%d2
+bcc.s __cbscanf_whitespace2
+2:
+subq.w #1,%d1 |last char is not whitespace
+beq.s __cbscanf_return |no whitespace = error
+bsr.s __cbscanf_ungetc
+bra __cbscanf_next
+
+__cbscanf_conversion_skip_whitespace:
+bsr.s __cbscanf_getc
+cmp.b #32,%d2
+beq.s __cbscanf_conversion_skip_whitespace
+cmp.b #13,%d2
+bhi.s 12f
+cmp.b #9,%d2
+bcc.s __cbscanf_conversion_skip_whitespace
+12:
+bra.s __cbscanf_ungetc |bsr+rts = bra
+
+__cbscanf_conversion:
+moveq.l #0,%d3 |flags
+clr.w %d5 |field width
+3:
+move.b (%a3)+,%d1 |current format character
+cmp.b #'*',%d1
+bne.s 4f
+bset.l #0,%d3
+bra.s 3b
+4:
+cmp.b #'h',%d1
+bne.s 5f
+btst.l #2,%d3
+bne __cbscanf_return
+bset.l #1,%d3
+bra.s 3b
+5:
+cmp.b #'l',%d1
+bne.s 6f
+btst.l #1,%d3
+bne __cbscanf_return
+bset.l #2,%d3
+bra.s 3b
+6:
+
+|read field width
+cmp.b #'0',%d1
+bcs.s 9f
+cmp.b #'9',%d1
+bhi.s 9f
+subi.b #'0',%d1
+ext.w %d1
+mulu.w #10,%d5
+add.w %d1,%d5
+bra.s 3b
+9:
+move.w %d5,%d6
+
+cmp.b #'%',%d1
+beq __cbscanf_literal
+
+|now, the next char must be a conversion
+cmp.b #'i',%d1
+bne.s __cbscanf_conversion_not_i
+moveq.l #0,%d7
+btst.l #0,%d3
+bne.s 27f
+move.l (%a4)+,%a6
+27:
+bsr __cbscanf_conversion_skip_whitespace
+__cbscanf_conversion_i_next:
+bsr __cbscanf_getc
+cmp.b #'-',%d2
+beq.s __cbscanf_conversion_i_neg
+cmp.b #173,%d2
+beq.s __cbscanf_conversion_i_neg
+cmp.b #'0',%d2
+bne.s __cbscanf_conversion_d_continue_as_u
+subq.w #1,%d6
+beq __cbscanf_conversion_u_finish
+bsr __cbscanf_getc
+cmp.b #'X',%d2
+beq.s 28f
+cmp.b #'x',%d2
+bne __cbscanf_conversion_i_continue_as_o
+28:
+subq.w #1,%d6
+beq __cbscanf_conversion_u_finish
+bsr __cbscanf_getc
+bra __cbscanf_conversion_i_continue_as_x
+__cbscanf_conversion_i_neg:
+bchg.l #3,%d3
+subq.w #1,%d6
+beq.s __cbscanf_conversion_u_finish
+bra.s __cbscanf_conversion_i_next
+__cbscanf_conversion_not_i:
+
+cmp.b #'d',%d1
+bne.s __cbscanf_conversion_not_d
+moveq.l #0,%d7
+btst.l #0,%d3
+bne.s 20f
+move.l (%a4)+,%a6
+20:
+bsr __cbscanf_conversion_skip_whitespace
+__cbscanf_conversion_d_next:
+bsr __cbscanf_getc
+cmp.b #'-',%d2
+beq.s 21f
+cmp.b #173,%d2
+bne.s __cbscanf_conversion_d_continue_as_u
+21:
+bchg.l #3,%d3
+subq.w #1,%d6
+beq.s __cbscanf_conversion_u_finish
+bra.s __cbscanf_conversion_d_next
+__cbscanf_conversion_not_d:
+
+cmp.b #'u',%d1
+bne.s __cbscanf_conversion_not_u
+moveq.l #0,%d7
+btst.l #0,%d3
+bne.s 17f
+move.l (%a4)+,%a6
+17:
+bsr __cbscanf_conversion_skip_whitespace
+__cbscanf_conversion_u_next:
+bsr __cbscanf_getc
+__cbscanf_conversion_d_continue_as_u:
+cmp.b #'0',%d2
+bcs.s __cbscanf_conversion_u_unget
+cmp.b #'9',%d2
+bhi.s __cbscanf_conversion_u_unget
+subi.b #'0',%d2
+ext.w %d2
+ext.l %d2
+add.l %d7,%d7
+move.l %d7,-(%a7)
+lsl.l #2,%d7
+add.l (%a7)+,%d7
+add.l %d2,%d7
+subq.w #1,%d6
+bne.s __cbscanf_conversion_u_next
+bra.s __cbscanf_conversion_u_finish
+__cbscanf_conversion_u_unget:
+bsr __cbscanf_ungetc
+__cbscanf_conversion_u_finish:
+btst.l #0,%d3
+bne __cbscanf_conversion_check
+btst.l #3,%d3
+beq.s 19f
+neg.l %d7
+19:
+btst.l #2,%d3
+bne.s 18f
+move.w %d7,(%a6)
+bra __cbscanf_conversion_check
+18:
+move.l %d7,(%a6)
+bra __cbscanf_conversion_check
+__cbscanf_conversion_not_u:
+
+cmp.b #'x',%d1
+beq.s 7f
+cmp.b #'X',%d1
+bne.s __cbscanf_conversion_not_x
+7:
+__cbscanf_conversion_hexadecimal:
+moveq.l #0,%d7
+btst.l #0,%d3
+bne.s 22f
+move.l (%a4)+,%a6
+22:
+bsr __cbscanf_conversion_skip_whitespace
+__cbscanf_conversion_x_next:
+bsr __cbscanf_getc
+__cbscanf_conversion_i_continue_as_x:
+cmp.b #'0',%d2
+bcs.s __cbscanf_conversion_u_unget
+cmp.b #'9',%d2
+bhi.s 23f
+subi.b #'0',%d2
+bra.s 25f
+23:
+cmp.b #'A',%d2
+bcs.s __cbscanf_conversion_u_unget
+cmp.b #'F',%d2
+bhi.s 24f
+subi.b #'A'-10,%d2
+bra.s 25f
+24:
+cmp.b #'a',%d2
+bcs.s __cbscanf_conversion_u_unget
+cmp.b #'f',%d2
+bhi.s __cbscanf_conversion_u_unget
+subi.b #'a'-10,%d2
+25:
+ext.w %d2
+ext.l %d2
+lsl.l #4,%d7
+add.l %d2,%d7
+subq.w #1,%d6
+bne.s __cbscanf_conversion_x_next
+bra __cbscanf_conversion_u_finish
+__cbscanf_conversion_not_x:
+
+cmp.b #'p',%d1
+bne.s __cbscanf_conversion_not_p
+bclr.l #1,%d3
+bset.l #2,%d3 |p=lx
+bra.s __cbscanf_conversion_hexadecimal
+__cbscanf_conversion_not_p:
+
+cmp.b #'o',%d1
+bne.s __cbscanf_conversion_not_o
+bsr __cbscanf_conversion_skip_whitespace
+moveq.l #0,%d7
+btst.l #0,%d3
+bne.s 26f
+move.l (%a4)+,%a6
+26:
+bsr __cbscanf_conversion_skip_whitespace
+__cbscanf_conversion_o_next:
+bsr __cbscanf_getc
+__cbscanf_conversion_i_continue_as_o:
+cmp.b #'0',%d2
+bcs __cbscanf_conversion_u_unget
+cmp.b #'7',%d2
+bhi __cbscanf_conversion_u_unget
+subi.b #'0',%d2
+ext.w %d2
+ext.l %d2
+lsl.l #3,%d7
+add.l %d2,%d7
+subq.w #1,%d6
+bne.s __cbscanf_conversion_o_next
+bra __cbscanf_conversion_u_finish
+__cbscanf_conversion_not_o:
+
+cmp.b #'f',%d1
+beq.s 8f
+cmp.b #'e',%d1
+beq.s 8f
+cmp.b #'g',%d1
+beq.s 8f
+cmp.b #'E',%d1
+bne __cbscanf_conversion_not_f
+8:
+bsr __cbscanf_conversion_skip_whitespace
+tst.w %d5 |default/maximum is 29 chars (not 100% ANSI compliant, but who cares?)
+beq.s 30f
+cmp.l #29,%d5
+bls.s 31f
+30:
+moveq.l #29,%d5
+moveq.l #29,%d6
+31:
+lea.l -30(%a7),%a7 |buffer
+move.l %a7,%a6
+__cbscanf_conversion_f_next:
+bsr __cbscanf_getc
+cmp.w #-1,%d2
+beq.s __cbscanf_conversion_f_unget
+cmp.b #'.',%d2
+beq.s 32f
+cmp.b #'0',%d2
+bcs.s __cbscanf_conversion_f_unget
+cmp.b #'9',%d2
+bls.s 32f
+cmp.b #149,%d2
+beq.s 32f
+cmp.b #173,%d2
+bne.s __cbscanf_conversion_f_unget
+32:
+move.b %d2,(%a6)+
+subq.w #1,%d6
+bne.s __cbscanf_conversion_f_next
+bra.s __cbscanf_conversion_f_add_nul
+__cbscanf_conversion_f_unget:
+bsr __cbscanf_ungetc
+__cbscanf_conversion_f_add_nul:
+clr.b (%a6)+
+movem.l %d0-%d2/%a0-%a1,-(%a7)
+pea.l 5*4(%a7)
+jsr atof
+addq.l #4,%a7
+cmp.l #0x7fffaa00,%d0
+bne.s 33f
+tst.l %d1
+bne.s 33f
+tst.w %d2
+beq.s __cbscanf_conversion_f_nan
+33:
+btst.l #0,%d3
+bne.s 34f
+move.l (%a4)+,%a6
+move.l %d0,(%a6)+
+move.l %d1,(%a6)+
+move.w %d2,(%a6)
+34:
+movem.l (%a7)+,%d0-%d2/%a0-%a1
+lea.l 30(%a7),%a7
+bra __cbscanf_conversion_check
+__cbscanf_conversion_f_nan:
+movem.l (%a7)+,%d0-%d2/%a0-%a1
+lea.l 30(%a7),%a7
+bra __cbscanf_return
+__cbscanf_conversion_not_f:
+
+cmp.b #'s',%d1
+bne.s __cbscanf_conversion_not_s
+btst.l #0,%d3
+bne.s 10f
+move.l (%a4)+,%a6
+10:
+bsr __cbscanf_conversion_skip_whitespace
+__cbscanf_conversion_s_next:
+bsr __cbscanf_getc
+cmp.w #-1,%d2
+beq.s __cbscanf_conversion_s_unget
+cmp.b #32,%d2
+beq.s __cbscanf_conversion_s_unget
+cmp.b #13,%d2
+bhi.s 13f
+cmp.b #9,%d2
+bcc.s __cbscanf_conversion_s_unget
+13:
+btst.l #0,%d3
+bne.s 14f
+move.b %d2,(%a6)+
+14:
+subq.w #1,%d6
+bne.s __cbscanf_conversion_s_next
+bra.s __cbscanf_conversion_s_add_nul
+__cbscanf_conversion_s_unget:
+bsr __cbscanf_ungetc
+__cbscanf_conversion_s_add_nul:
+btst.l #0,%d3
+bne __cbscanf_conversion_check
+clr.b (%a6)+
+bra __cbscanf_conversion_check
+__cbscanf_conversion_not_s:
+
+cmp.b #'[',%d1
+bne __cbscanf_conversion_not_set
+tst.b (%a3)
+beq __cbscanf_return
+cmp.b #'^',(%a3)
+bne.s 38f
+addq.l #1,%a3
+tst.b (%a3)
+beq __cbscanf_return
+bset.l #3,%d3
+38:
+btst.l #0,%d3
+bne.s 35f
+move.l (%a4)+,%a6
+35:
+__cbscanf_conversion_set_next:
+bsr __cbscanf_getc
+cmp.w #-1,%d2
+beq.s __cbscanf_conversion_set_unget
+|check if in set
+pea.l (%a3)
+tst.b (%a3)
+beq.s 39f
+cmp.b (%a3)+,%d2
+beq.s 36f
+43:
+move.b (%a3)+,%d1
+beq.s 39f
+cmp.b #']',%d1
+beq.s 39f
+cmp.b #'-',%d1
+bne.s 40f
+move.b (%a3)+,%d1
+beq.s 39f
+cmp.b #']',%d1
+beq.s 42f
+cmp.b %d1,%d2
+bhi.s 43b
+cmp.b -2(%a3),%d2
+bcs.s 43b
+bra.s 36f
+40:
+cmp.b %d1,%d2
+beq.s 36f
+bra.s 43b
+42:
+cmp.b #'-',%d2
+beq.s 36f
+39: |not in set
+movea.l (%a7)+,%a3
+btst.l #3,%d3
+bne.s 41f
+bra.s __cbscanf_conversion_set_unget
+36: |in set
+movea.l (%a7)+,%a3
+btst.l #3,%d3
+bne.s __cbscanf_conversion_set_unget
+41:
+btst.l #0,%d3
+bne.s 37f
+move.b %d2,(%a6)+
+37:
+subq.w #1,%d6
+bne.s __cbscanf_conversion_set_next
+bra.s __cbscanf_conversion_set_add_nul
+__cbscanf_conversion_set_unget:
+bsr __cbscanf_ungetc
+__cbscanf_conversion_set_add_nul:
+addq.l #1,%a3
+47:
+tst.b (%a3)
+beq __cbscanf_return
+cmp.b #']',(%a3)+
+bne.s 47b
+bra __cbscanf_conversion_s_add_nul
+__cbscanf_conversion_not_set:
+
+cmp.b #'c',%d1
+bne.s __cbscanf_conversion_not_c
+btst.l #0,%d3
+bne.s 11f
+move.l (%a4)+,%a6
+11:
+tst.w %d5 |default is 1 char
+bne.s 15f
+addq.w #1,%d5
+addq.w #1,%d6
+15:
+__cbscanf_conversion_c_next:
+bsr __cbscanf_getc
+cmp.w #-1,%d2
+beq.s __cbscanf_conversion_check
+btst.l #0,%d3
+bne.s 16f
+move.b %d2,(%a6)+
+16:
+subq.w #1,%d6
+bne.s __cbscanf_conversion_c_next
+bra.s __cbscanf_conversion_check
+__cbscanf_conversion_not_c:
+
+cmp.b #'n',%d1
+bne.s __cbscanf_conversion_not_n
+btst.l #0,%d3
+bne.s __cbscanf_conversion_no_check
+move.l (%a4)+,%a6
+move.w %d4,(%a6)
+bra.s __cbscanf_conversion_no_check
+__cbscanf_conversion_not_n:
+
+__cbscanf_conversion_check:
+cmp.w %d5,%d6
+beq __cbscanf_return
+__cbscanf_conversion_no_check:
+btst.l #0,%d3
+bne.s 44f
+addq.w #1,%d0 |count successful conversion
+44:
+bra __cbscanf_next

+ 12 - 0
tigcc/archive/clrscr.s

@@ -0,0 +1,12 @@
+	.xdef clrscr
+
+.text
+clrscr:
+	move.l 0xC8,%a0
+	move.l (%a0,0x674),%a0 /* MoveTo */
+	clr.l -(%sp)
+	jsr (%a0)
+	addq.l #4,%sp
+	move.l 0xC8,%a0
+	move.l (%a0,0x678),%a0 /* ClrScr */
+	jmp (%a0)

+ 12 - 0
tigcc/archive/cmpbf.s

@@ -0,0 +1,12 @@
+	.xdef __cmpbf2,__nebf2,__eqbf2,__gebf2,__ltbf2,__gtbf2,__lebf2
+
+.text
+__cmpbf2:
+__nebf2:
+__eqbf2:
+__gebf2:
+__ltbf2:
+__gtbf2:
+__lebf2:
+	moveq.l #20,%d0
+	jra __fp_entry_1

+ 10 - 0
tigcc/archive/contrastdn.s

@@ -0,0 +1,10 @@
+	.xdef OSContrastDn
+
+.text
+OSContrastDn:
+	movem.l %d3-%d4,-(%sp)
+	move.l 0xC8,%a0
+	move.l (%a0,2652),%a0
+	jsr (%a0)
+	movem.l (%sp)+,%d3-%d4
+	rts

+ 10 - 0
tigcc/archive/contrastup.s

@@ -0,0 +1,10 @@
+	.xdef OSContrastUp
+
+.text
+OSContrastUp:
+	movem.l %d3-%d4,-(%sp)
+	move.l 0xC8,%a0
+	move.l (%a0,2648),%a0
+	jsr (%a0)
+	movem.l (%sp)+,%d3-%d4
+	rts

+ 6 - 0
tigcc/archive/divbf.s

@@ -0,0 +1,6 @@
+	.xdef __divbf3
+
+.text
+__divbf3:
+	moveq.l #12,%d0
+	jra __fp_entry

+ 37 - 0
tigcc/archive/divdi.s

@@ -0,0 +1,37 @@
+|divdi3 routine copyright (C) 2002, Kevin Kofler
+|WARNING: Division by 0 will be handled the same way as in the unsigned variant.
+|         For my __udivdi3, this means:
+|         A division by 0 will not cause an exception, but just crash in an
+|         infinite loop!
+|ANOTHER WARNING: This will ONLY work with an __udivdi3 which does NOT destroy a1!
+|                 Mine works of course.
+
+	.xdef __divdi3
+
+.text
+__divdi3:
+	tst.b 4(%a7)
+	blt.s .L__divdi3_numer_negative
+	tst.b 12(%a7)	
+	blt.s .L__divdi3_denom_negative
+.L__divdi3_udivdi3:
+	jbra __udivdi3
+
+.L__divdi3_numer_negative:
+	neg.l 8(%a7)
+	negx.l 4(%a7)
+	tst.b 12(%a7)	
+	bge.s .L__divdi3_denom_positive
+	neg.l 16(%a7)
+	negx.l 12(%a7)
+	bra.s .L__divdi3_udivdi3
+
+.L__divdi3_denom_negative:
+	neg.l 16(%a7)
+	negx.l 12(%a7)
+.L__divdi3_denom_positive:
+	move.l (%a7)+,%a1
+	bsr.s .L__divdi3_udivdi3
+	neg.l %d1
+	negx.l %d0
+	jmp (%a1)

+ 11 - 0
tigcc/archive/diventry.s

@@ -0,0 +1,11 @@
+	.xdef __div_entry
+
+.text
+__div_entry:
+	move.l (4,%sp),%d1
+	move.l (8,%sp),%d0
+	movea.l 0xC8,%a0
+	movea.l (%a0,%d2.w),%a0
+	jsr (%a0)
+	move.l %d1,%d0
+	rts

+ 6 - 0
tigcc/archive/divsi.s

@@ -0,0 +1,6 @@
+	.xdef __divsi3
+
+.text
+__divsi3:
+	move.w #0x2A8*4,%d2 /* _ds32s32 */
+	jra __div_entry

+ 71 - 0
tigcc/archive/dll.c

@@ -0,0 +1,71 @@
+#include <compat.h>
+#include <dll.h>
+#include <alloc.h>
+#include <vat.h>
+#include <string.h>
+#include <system.h>
+#include <peekpoke.h>
+
+/* These functions are in the same file, so that they
+   can access their global variables in a pc-relative
+   fashion. */
+
+__ATTR_LIB_C__ short LoadDLL(const char *DLL_name, long ID, short major, short minor)
+{
+  SYM_ENTRY *entry;
+  HANDLE h;
+  unsigned char *bptr,*sptr;
+  unsigned short len,offset=0,wrongver=0;
+  unsigned long pc;
+  unsigned long signature[]={__DLL_SIGNATURE,ID};
+  asm volatile("bsr 0f; 0:move.l (%%sp)+,%0":"=g"(pc));
+  if(HW_VERSION==2 && pc<0x40000) return DLL_NOTINGHOSTSPACE;
+  if(__DLL_body_ptr) return DLL_ALREADYLOADED;
+  entry=SymFindFirst(NULL,2);
+  do
+    {
+      if(!strcmp(entry->name,DLL_name)&&entry->handle&&!entry->flags.bits.twin
+        &&(entry->flags.bits.archived||!HeapGetLock(entry->handle)))
+          {
+            len=peek_w(bptr=HeapDeref(entry->handle))+2;
+            if(!memcmp(bptr+len-5,"DLL\x00\xF8",5))
+              {
+                offset=0;
+                for(sptr=bptr+2;(sptr<bptr+len-1)&&!offset;sptr+=2)
+                  if(!memcmp(sptr,signature,8))
+                    {
+                      if((unsigned short)major!=((__DLL_interface_struct*)sptr)->major
+                        ||(unsigned short)minor>((__DLL_interface_struct*)sptr)->minor)
+                          wrongver=1;
+                      else
+                        offset=sptr-bptr,wrongver=0;
+                    }
+                  if(offset) break;
+                }
+          }
+    } while((entry=SymFindNext()));
+  if(wrongver) return DLL_WRONGVERSION;
+  if(!entry) return DLL_NOTFOUND;
+  if(!HeapLock(h=entry->handle)) return DLL_LOCKFAILED;
+  if(!(__DLL_body_ptr=malloc(len=peek_w(bptr=HeapDeref(h)+2)+2))) 
+    {
+      HeapUnlock(h);
+      return DLL_OUTOFMEM;
+    }
+  memcpy(__DLL_body_ptr,bptr,len);
+  EX_patch((char*)__DLL_body_ptr+(HW_VERSION==2?0x40000:0)+2,(char*)__DLL_body_ptr+(HW_VERSION==2?0x40000:0)+len-1);
+  __DLL_interface_ptr=(__DLL_interface_struct*)((char*)__DLL_body_ptr+offset-2);
+  HeapUnlock(h);
+  return DLL_OK;
+}
+
+__ATTR_LIB_C__ void UnloadDLL(void)
+{
+  if(!__DLL_body_ptr) return;
+  free(__DLL_body_ptr);
+  __DLL_body_ptr=0;
+  __DLL_interface_ptr=0;
+}
+
+__DLL_interface_struct *__DLL_interface_ptr=0;
+void *__DLL_body_ptr=0;

+ 245 - 0
tigcc/archive/dll.s

@@ -0,0 +1,245 @@
+	.file	"dll.c"
+#NO_APP
+	.text
+tigcc_compiled.:
+#APP
+	.set _A_LINE,0xA000
+#NO_APP
+	.section	.rodata.__unalignedstr,"dmu"
+.LC0:
+	.ascii "DLL\0\370\0"
+	.text
+	.even
+	.globl	LoadDLL
+LoadDLL:
+	link.w %a6,#-12
+	movm.l #0x1f3c,-(%sp)
+	move.l %a0,%d7
+	move.w %d1,%d6
+	move.w %d2,%d5
+	clr.w -10(%a6)
+	clr.w %d4
+	move.l #1145850912,-8(%a6)
+	move.l %d0,-4(%a6)
+#APP
+	bsr 0f; 0:move.l (%sp)+,%d3
+#NO_APP
+	lea __get_hw_version,%a5
+	jbsr (%a5)
+	cmp.w #2,%d0
+	jbne .L2
+	moveq.l #1,%d1
+	cmp.l #262143,%d3
+	jbls .L1
+.L2:
+	tst.l __DLL_body_ptr
+	jbeq .L3
+	moveq.l #5,%d1
+	jbra .L1
+	.even
+.L3:
+	move.l 200.w,%a0
+	move.w #2,-(%sp)
+	clr.l -(%sp)
+	move.l 432(%a0),%a0
+	jbsr (%a0)
+	move.l %a0,%a4
+	addq.l #6,%sp
+.L4:
+	move.l 200.w,%a0
+	move.l %d7,-(%sp)
+	move.l %a4,-(%sp)
+	move.l 2500(%a0),%a0
+	jbsr (%a0)
+	addq.l #8,%sp
+	tst.w %d0
+	jbne .L6
+	move.w 12(%a4),%d1
+	jbeq .L6
+	move.b 10(%a4),%d0
+	btst #2,%d0
+	jbne .L6
+	btst #1,%d0
+	jbne .L8
+	move.l 200.w,%a0
+	move.w %d1,-(%sp)
+	move.l 620(%a0),%a0
+	jbsr (%a0)
+	addq.l #2,%sp
+	tst.w %d0
+	jbne .L6
+.L8:
+	move.l 200.w,%a0
+	move.w 12(%a4),-(%sp)
+	move.l 600(%a0),%a0
+	jbsr (%a0)
+	move.l %a0,%a3
+	move.w (%a0),%d3
+	addq.w #2,%d3
+	move.l 200.w,%a0
+	pea 5.w
+	pea .LC0
+	clr.l %d0
+	move.w %d3,%d0
+	pea -5(%a3,%d0.l)
+	move.l 2496(%a0),%a0
+	jbsr (%a0)
+	lea (14,%sp),%sp
+	tst.w %d0
+	jbne .L6
+	clr.w -10(%a6)
+	lea (2,%a3),%a2
+	jbra .L10
+	.even
+.L19:
+	move.l 200.w,%a0
+	pea 8.w
+	pea -8(%a6)
+	move.l %a2,-(%sp)
+	move.l 2496(%a0),%a0
+	jbsr (%a0)
+	lea (12,%sp),%sp
+	tst.w %d0
+	jbne .L12
+	cmp.w 8(%a2),%d6
+	jbne .L17
+	cmp.w 10(%a2),%d5
+	jbls .L16
+.L17:
+	moveq.l #1,%d4
+	jbra .L12
+	.even
+.L16:
+	move.w %a2,%d0
+	sub.w %a3,%d0
+	move.w %d0,-10(%a6)
+	clr.w %d4
+.L12:
+	addq.l #2,%a2
+.L10:
+	clr.l %d0
+	move.w %d3,%d0
+	lea -1(%a3,%d0.l),%a0
+	cmp.l %a2,%a0
+	jbls .L11
+	tst.w -10(%a6)
+	jbeq .L19
+.L11:
+	tst.w -10(%a6)
+	jbne .L5
+.L6:
+	move.l 200.w,%a0
+	move.l 436(%a0),%a0
+	jbsr (%a0)
+	move.l %a0,%a4
+	cmp.w #0,%a0
+	jbne .L4
+.L5:
+	moveq.l #6,%d1
+	tst.w %d4
+	jbne .L1
+	moveq.l #2,%d1
+	cmp.w #0,%a4
+	jbeq .L1
+	move.l 200.w,%a0
+	move.w 12(%a4),%a4
+	move.w %a4,-(%sp)
+	move.l 616(%a0),%a0
+	jbsr (%a0)
+	addq.l #2,%sp
+	moveq.l #3,%d1
+	tst.w %d0
+	jbeq .L1
+	move.l 200.w,%a2
+	move.w %a4,-(%sp)
+	move.l 600(%a2),%a0
+	jbsr (%a0)
+	addq.l #2,%sp
+	lea (2,%a0),%a3
+	move.w (%a3),%d3
+	addq.w #2,%d3
+	and.l #0xFFFF,%d3
+	move.l %d3,-(%sp)
+	move.l 648(%a2),%a0
+	jbsr (%a0)
+	move.l %a0,%d0
+	move.l %a0,__DLL_body_ptr
+	addq.l #4,%sp
+	move.l 200.w,%a0
+	tst.l %d0
+	jbne .L25
+	move.w %a4,-(%sp)
+	move.l 636(%a0),%a0
+	jbsr (%a0)
+	moveq.l #4,%d1
+	addq.l #2,%sp
+	jbra .L1
+	.even
+.L25:
+	move.l %d3,-(%sp)
+	move.l %a3,-(%sp)
+	move.l %d0,-(%sp)
+	move.l 2472(%a0),%a0
+	jbsr (%a0)
+	move.l 200.w,%a2
+	jbsr (%a5)
+	move.l __DLL_body_ptr,%a0
+	lea -1(%a0,%d3.l),%a1
+	cmp.w #2,%d0
+	jbne .L27
+	add.l %d3,%a0
+	move.l #262143,%a1
+	add.l %a0,%a1
+.L27:
+	move.l %a1,-(%sp)
+	jbsr (%a5)
+	move.l __DLL_body_ptr,%a0
+	move.l 1384(%a2),%a2
+	move.l #262146,%a1
+	add.l %a0,%a1
+	cmp.w #2,%d0
+	jbeq .L29
+	lea (2,%a0),%a1
+.L29:
+	move.l %a1,-(%sp)
+	jbsr (%a2)
+	clr.l %d0
+	move.w -10(%a6),%d0
+	add.l __DLL_body_ptr,%d0
+	subq.l #2,%d0
+	move.l %d0,__DLL_interface_ptr
+	move.l 200.w,%a0
+	move.w %a4,-(%sp)
+	move.l 636(%a0),%a0
+	jbsr (%a0)
+	clr.w %d1
+	lea (22,%sp),%sp
+.L1:
+	move.w %d1,%d0
+	movm.l -48(%a6),#0x3cf8
+	unlk %a6
+	rts
+	.even
+	.globl	UnloadDLL
+UnloadDLL:
+	move.l __DLL_body_ptr,%d0
+	jbeq .L30
+	move.l 200.w,%a0
+	move.l %d0,-(%sp)
+	move.l 652(%a0),%a0
+	jbsr (%a0)
+	clr.l __DLL_body_ptr
+	clr.l __DLL_interface_ptr
+	addq.l #4,%sp
+.L30:
+	rts
+	nop
+	.globl	__DLL_interface_ptr
+	.text
+	.even
+__DLL_interface_ptr:
+	.long	0
+	.globl	__DLL_body_ptr
+	.even
+__DLL_body_ptr:
+	.long	0

+ 5 - 0
tigcc/archive/dummyhandler.s

@@ -0,0 +1,5 @@
+	.xdef __dummy_handler__
+
+.text
+__dummy_handler__:
+	rte

+ 6 - 0
tigcc/archive/enter_ghost_space.s

@@ -0,0 +1,6 @@
+	.xdef enter_ghost_space
+
+	.xdef __ref_all___enter_ghost_space
+
+.section _st10500
+enter_ghost_space:

+ 8 - 0
tigcc/archive/enter_ghost_space_1.s

@@ -0,0 +1,8 @@
+	.xdef __enter_ghost_space_AND___complex_main
+
+.section _st10501
+| In case of a complex _main (i.e. called with jbsr
+| instead of jra), modify the return address to stay
+| in the ghost space.
+	move.l __save__sp__,%a0
+	or.l #0x40000,(%a0)

+ 87 - 0
tigcc/archive/enter_ghost_space_2.s

@@ -0,0 +1,87 @@
+	.xdef __enter_ghost_space
+
+.section _st10502
+	bsr.w .L__ghost_space_0
+.L__ghost_space_0:
+	move.l (%sp)+,%d0
+	cmpi.l #0x40000,%d0
+	bcc .L__ghost_space_2
+	movea.l 0xC8,%a0
+	cmpi.l #1000,(%a0,-4)
+	bcs .L__ghost_space_2
+	movem.l %a2-%a6/%d3-%d7,-(%sp)
+	lea (%sp,-20),%sp
+	move.l #0x3E000,%a3
+	move.l %a0,%d0
+	andi.l #0xE00000,%d0
+	addi.l #0x20000,%d0
+	move.l %d0,(%sp,12)
+	move.l %d0,(%sp,16)
+	trap #0xC
+	move.w #0x2700,%sr
+	move.l #0xF,%d3
+	pea .L__ghost_space_1(%pc)
+	bset.b #2,(%sp,1)
+	clr.w  -(%sp)
+	move.l 0xAC,%a0
+	jmp (%a0)
+.L__ghost_space_1:
+	lea (%sp,20),%sp
+	movem.l (%sp)+,%a2-%a6/%d3-%d7
+
+| The following code was compiled from:
+|
+|    /* If we are on AMS 2, we have to set the "last executed program" to somewhere
+|       in the last 4 KB of RAM, or else APD may crash under certain circumstances.
+|       The code below looks for the "last executed program" variable. That variable
+|       is cleared during initialization, immediately after the stack fence is set up.
+|       So we look for the value of the stack fence (0xDEADDEAD) in the initialization
+|       code and add 8 to get the wanted short pointer, which must then be
+|       sign-extended to an actual pointer. (The sign extension is implicit in the
+|       generated code, as it should be.) */
+|    if (!(AMS_1xx||*(short*)0x32==('R'<<8)+'O')) {
+|      /* rb and q are factored out in order to get more efficient code. */
+|      char *rb=ROM_base;
+|      char *p=rb+0x12000;
+|      char *q=rb+0x18000;
+|
+|      while (p<q && *(unsigned long*)p!=0xDEADDEAD) p+=2;
+|      p+=2[(short *)p]?8:12;
+|      *(void **)(long)*(short *)p=(void*)0x3f000;
+|    }
+
+	move.l 0xC8,%d0
+	move.l %d0,%a0
+	cmp.l #999,-4(%a0)
+	jbls .L1
+	cmp.w #0x524F,0x32
+	jbeq .L1
+	and.l #0xE00000,%d0
+	move.l %d0,%a0
+	add.l #0x12000,%a0
+	add.l #0x18000,%d0
+	jbra .L3
+	.even
+.L7:
+	addq.l #2,%a0
+.L3:
+	cmp.l %a0,%d0
+	jbls .L4
+	cmp.l #0xDEADDEAD,(%a0)
+	jbne .L7
+.L4:
+	tst.w 4(%a0)
+	bne.s 0f
+	addq.l #4,%a0
+0:
+	move.w 8(%a0),%a0
+	move.l #0x3F000,(%a0)
+.L1:
+
+| End compiled code.
+
+.L__ghost_space_2:
+	move.l (%sp)+,%d0
+	bset.l #18,%d0
+	movea.l %d0,%a0
+	jmp (%a0)

+ 13 - 0
tigcc/archive/exit.s

@@ -0,0 +1,13 @@
+|exit function copyright (C) 2002, Kevin Kofler
+|requires new exit support (__save__sp__)
+|Thanks to Patrick Pélissier for the code. I have just changed it from a patch
+|to an archive function, so it won't be there when not needed.
+
+	.xdef __exit
+
+| This file requires the startup exit support.
+	.xdef __ref_all___save_all_registers_main
+
+__exit:
+	movea.l __save__sp__:l,%a7 |(NOT PC-relative because of programs >32 KB)
+	rts

+ 32 - 0
tigcc/archive/fargo.tpr

@@ -0,0 +1,32 @@
+[Settings]
+Archive=1
+Use Data Variable=0
+Data Variable=
+Copy Data Variable=1
+Copy Data Variable if Archived=1
+Pack=0
+Packed Variable=
+Project Name=libf021
+GCC Switches=-Os -Wall -W -Wwrite-strings
+GNU Assembler Switches=
+Assembler Switches=-g -t
+Debug Info=0
+Standard Library=1
+Optimize NOPs=1
+Optimize Returns=1
+Optimize Branches=1
+Optimize Moves=1
+Optimize Tests=1
+Optimize Calculations=1
+Remove Unused Sections=1
+Binary Output=0
+Command Line=
+Post-Build Process=
+Fargo=0
+Cut Unused Ranges=1
+
+[Included Files]
+GNU Assembler File 1=startup\_fargo021_library_header.s
+GNU Assembler File 1 Folder=startup
+GNU Assembler File 2=startup\_fargo021_program_header.s
+GNU Assembler File 2 Folder=startup

+ 16 - 0
tigcc/archive/fclose.c

@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include <alloc.h>
+
+__ATTR_LIB_C__ short fclose(FILE *f)
+{
+  short s;
+  
+  if(!f) return EOF;
+  s=(f->flags&_F_ERR)?EOF:0;
+  
+  if(f->flags&_F_WRIT) HeapRealloc(f->handle,(*(unsigned short*)(f->base))+2);
+  HeapUnlock(f->handle);
+  free(f);
+  
+  return s;
+}

+ 49 - 0
tigcc/archive/fclose.s

@@ -0,0 +1,49 @@
+	.file	"fclose.c"
+#NO_APP
+	.text
+tigcc_compiled.:
+#APP
+	.set _A_LINE,0xA000
+#NO_APP
+	.text
+	.even
+	.globl	fclose
+fclose:
+	move.l %a2,-(%sp)
+	move.l %d3,-(%sp)
+	move.l %a0,%a2
+	moveq.l #-1,%d0
+	cmp.w #0,%a0
+	jbeq .L1
+	move.w 10(%a0),%d0
+	move.w %d0,%d3
+	and.w #16,%d3
+	lsr.w #4,%d3
+	neg.w %d3
+	and.w #2,%d0
+	jbeq .L5
+	move.l 200.w,%a1
+	move.l 4(%a0),%a0
+	move.w (%a0),%d0
+	addq.w #2,%d0
+	move.w %d0,-(%sp)
+	clr.w -(%sp)
+	move.w 8(%a2),-(%sp)
+	move.l 628(%a1),%a0
+	jbsr (%a0)
+	addq.l #6,%sp
+.L5:
+	move.l 200.w,%a0
+	move.w 8(%a2),-(%sp)
+	move.l 636(%a0),%a0
+	jbsr (%a0)
+	move.l 200.w,%a0
+	move.l %a2,-(%sp)
+	move.l 652(%a0),%a0
+	jbsr (%a0)
+	move.w %d3,%d0
+	addq.l #6,%sp
+.L1:
+	move.l (%sp)+,%d3
+	move.l (%sp)+,%a2
+	rts

+ 18 - 0
tigcc/archive/fgetc.c

@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <peekpoke.h>
+
+__ATTR_LIB_C__ short fgetc(FILE *f)
+{
+  short c,tmode=!(f->flags&_F_BIN);
+  if(f->flags&_F_ERR) return EOF;
+  if(!(f->flags&_F_READ)) __FERROR(f);
+  if((c=f->unget)<0)
+    {
+      f->unget=0; return c&0xFF;
+    }
+  if(feof(f)) return EOF;
+  c=peek(f->fpos++);
+  if(c=='\r'&&tmode) fgetc(f);
+  if(f->base+peek_w(f->base)+(tmode?0:2)==f->fpos) f->flags|=_F_EOF;
+  return c;
+}

+ 71 - 0
tigcc/archive/fgetc.s

@@ -0,0 +1,71 @@
+	.file	"fgetc.c"
+#NO_APP
+	.text
+tigcc_compiled.:
+#APP
+	.set _A_LINE,0xA000
+#NO_APP
+	.text
+	.even
+	.globl	fgetc
+fgetc:
+	movm.l #0x1820,-(%sp)
+	move.l %a0,%a2
+	move.w 10(%a0),%d1
+	move.w %d1,%d4
+	lsr.w #6,%d4
+	eor.w #1,%d4
+	and.w #1,%d4
+	move.w %d1,%d0
+	and.w #16,%d0
+	moveq.l #-1,%d2
+	tst.w %d0
+	jbne .L1
+	move.w %d1,%d0
+	and.w #1,%d0
+	jbne .L3
+	or.w #16,%d1
+	move.w %d1,10(%a0)
+	jbra .L1
+	.even
+.L3:
+	move.w 12(%a0),%d3
+	jbge .L4
+	clr.w 12(%a0)
+	move.w %d3,%d2
+	and.w #255,%d2
+	jbra .L1
+	.even
+.L4:
+	and.w #32,%d1
+	moveq.l #-1,%d2
+	tst.w %d1
+	jbne .L1
+	move.l (%a0),%a1
+	clr.w %d3
+	move.b (%a1),%d3
+	addq.l #1,(%a0)
+	cmp.w #13,%d3
+	jbne .L6
+	tst.w %d4
+	jbeq .L6
+	jbsr fgetc
+.L6:
+	move.l 4(%a2),%a0
+	clr.l %d0
+	move.w (%a0),%d0
+	add.l %a0,%d0
+	move.l (%a2),%d1
+	tst.w %d4
+	jbne .L9
+	addq.l #2,%d0
+.L9:
+	cmp.l %d0,%d1
+	jbne .L8
+	or.w #32,10(%a2)
+.L8:
+	move.w %d3,%d2
+.L1:
+	move.w %d2,%d0
+	movm.l (%sp)+,#0x418
+	rts

+ 54 - 0
tigcc/archive/fgetchar.s

@@ -0,0 +1,54 @@
+|improved fgetchar() implementation for TIGCCLIB
+|Copyright (C) Kevin Kofler, 2002-2003
+|Based on documentation examples and the original fgetchar implementation, both
+|by Zeljko Juric
+
+/* Prototype:
+   short fgetchar(void); */
+
+.text
+.xdef fgetchar
+
+__fgetchar_clipzone: .byte 0,0,239,127
+
+.equ __SaveScrState,0x1a0 /* SaveScrState */
+.equ __MoveTo,0x19d       /* MoveTo */
+.equ __DrawClipChar,0x191 /* DrawClipChar */
+
+fgetchar:
+movem.l %a2-%a4/%d3,-(%a7)
+5:
+link.w %a6,#-18
+pea.l (%a7)
+move.l 0xc8:w,%a2
+move.l __SaveScrState*4(%a2),%a0
+jsr (%a0)
+move.w #4,(%a7)
+pea.l __fgetchar_clipzone(%pc)
+move.w #'_',-(%a7)
+move.l -8(%a6),-(%a7)
+move.l __DrawClipChar*4(%a2),%a3
+jsr (%a3)
+jbsr __fgetchar
+move.w %d0,%d3
+move.w #2,(%a7)
+pea.l __fgetchar_clipzone(%pc)
+move.w #'_',-(%a7)
+move.l -8(%a6),-(%a7)
+jsr (%a3)
+move.l -8(%a6),(%a7)
+move.l __MoveTo*4(%a2),%a0
+jsr (%a0)
+cmp.w #255,%d3
+bhi.s 2f
+move.w %d3,(%a7)
+cmp.w #13,(%a7)
+bne.s 3f
+subq.w #3,(%a7)
+3:
+jbsr fputchar
+2:
+move.w %d3,%d0
+unlk %a6
+movem.l (%a7)+,%a2-%a4/%d3
+rts

+ 59 - 0
tigcc/archive/fgetchrc.s

@@ -0,0 +1,59 @@
+|improved fgetchar()/gets()/getsn() implementation for TIGCCLIB - core routine
+|Copyright (C) Kevin Kofler, 2002-2003
+|Based on documentation examples and the original fgetchar implementation, both
+|by Zeljko Juric
+
+/* Prototype:
+   short __fgetchar(void); */
+
+.xdef __ref_all___set_file_in_use_bit
+
+.text
+.xdef __fgetchar
+
+__fgetchar_CaptureHandler:
+move.l 4(%a7),%a0
+cmp.w #0x723,(%a0)
+bne.s 0f
+move.l 8(%a0),%a0
+lea.l __fgetchar_keycode+2(%pc),%a1
+clr.w %d0
+move.b (%a0),%d0
+move.w %d0,(%a1)
+0:
+rts
+
+.equ __ngetchx,0x51            /* ngetchx */
+.equ __EV_captureEvents,0xc6   /* EV_captureEvents */
+.equ __EV_defaultHandler,0x157 /* EV_defaultHandler */
+
+__fgetchar:
+pea.l (%a2)
+2:
+move.l 0xc8:w,%a2
+move.l __ngetchx*4(%a2),%a0
+jsr (%a0)
+cmp.w #4139,%d0
+bne.s 1f
+lea.l __fgetchar_keycode+2(%pc),%a0
+clr.w (%a0)
+pea.l __fgetchar_CaptureHandler(%pc)
+move.l __EV_captureEvents*4(%a2),%a2
+jsr (%a2)
+clr.w (%a7)
+move.w %d3,-(%a7)
+move.w #4096,-(%a7)
+subq.l #6,%a7
+move.w #0x710,-(%a7)
+pea.l (%a7)
+move.l __EV_defaultHandler*4(%a2),%a0
+jsr (%a0)
+clr.l (%a7)
+jsr (%a2)
+lea.l 16(%a7),%a7
+__fgetchar_keycode:
+move.w #0,%d0
+beq.s 2b
+1:
+movea.l (%a7)+,%a2
+rts

+ 14 - 0
tigcc/archive/fgets.c

@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+__ATTR_LIB_C__ char *fgets(char *s, short n, FILE *fp)
+{
+  short c=EOF;
+  char *cs=s;
+  while(--n>0&&(c=fgetc(fp))!=EOF)
+    {
+      if(c=='\r'&&!(fp->flags&_F_BIN)) c='\n';
+      if ((*cs++=c)=='\n') break;
+    }
+  *cs=0;
+  return ((c==EOF&&cs==s)?NULL:s);
+}

+ 52 - 0
tigcc/archive/fgets.s

@@ -0,0 +1,52 @@
+	.file	"fgets.c"
+#NO_APP
+	.text
+tigcc_compiled.:
+#APP
+	.set _A_LINE,0xA000
+#NO_APP
+	.text
+	.even
+	.globl	fgets
+fgets:
+	movm.l #0x1830,-(%sp)
+	move.l %a0,%d4
+	move.w %d0,%d3
+	move.l %a1,%a3
+	moveq.l #-1,%d1
+	move.l %a0,%a2
+	jbra .L2
+	.even
+.L8:
+	cmp.w #13,%d1
+	jbne .L6
+	move.w 10(%a3),%d0
+	and.w #64,%d0
+	jbne .L6
+	moveq.l #10,%d1
+.L6:
+	move.b %d1,(%a2)+
+	cmp.b #10,%d1
+	jbeq .L3
+.L2:
+	subq.w #1,%d3
+	tst.w %d3
+	jble .L3
+	move.l %a3,%a0
+	jbsr fgetc
+	move.w %d0,%d1
+	cmp.w #-1,%d0
+	jbne .L8
+.L3:
+	clr.b (%a2)
+	cmp.w #-1,%d1
+	jbne .L11
+	moveq.l #0,%d0
+	cmp.l %a2,%d4
+	jbeq .L10
+.L11:
+	move.l %d4,%d0
+.L10:
+	move.l %d0,%a0
+	movm.l (%sp)+,#0xc18
+	rts

+ 33 - 0
tigcc/archive/findprogramvar.c

@@ -0,0 +1,33 @@
+/* This routine will return a pointer to the SYM_ENTRY of the running program,
+or NULL in case it isn't found (e.g. if the program was exe-packed).
+Note: Do not call anything which may cause a heap compression between when
+this routine is called and when the pointer to it is used. Otherwise, the
+pointer may become invalid, causing a crash or other random, unexpected
+behavior. You can also use FolderOp to avoid this problem.
+
+Contributed by Joel Thompson */
+
+#include <vat.h>
+#include <alloc.h>
+
+__ATTR_LIB_C__ SYM_ENTRY *FindProgramVar (void)
+{
+  SYM_ENTRY *symptr;
+  unsigned char *program_counter;
+
+  asm volatile ("bsr 0f\n"
+                "0:move.l (%%sp)+,%0"
+                : "=g" (program_counter));
+  // In case the program is in the ghost space, AND out the extra bit(s).
+  ((unsigned long) program_counter) &= 0x3FFFF;
+
+  for (symptr = SymFindFirst (NULL, FO_RECURSE); symptr; symptr = SymFindNext ())
+  {
+    HANDLE handle = symptr->handle;
+    unsigned char *ptr = HeapDeref (symptr->handle);
+    if ((program_counter >= ptr) && (program_counter < ptr + HeapSize (handle)))
+      return symptr;
+  }
+
+  return NULL;
+}

+ 58 - 0
tigcc/archive/findprogramvar.s

@@ -0,0 +1,58 @@
+	.file	"findprogramvar.c"
+#NO_APP
+	.text
+tigcc_compiled.:
+#APP
+	.set _A_LINE,0xA000
+#NO_APP
+	.text
+	.even
+	.globl	FindProgramVar
+FindProgramVar:
+	movm.l #0x1c20,-(%sp)
+#APP
+	bsr 0f
+0:move.l (%sp)+,%d4
+#NO_APP
+	and.l #262143,%d4
+	move.l 200.w,%a0
+	move.w #2,-(%sp)
+	clr.l -(%sp)
+	move.l 432(%a0),%a0
+	jbsr (%a0)
+	move.l %a0,%a2
+	addq.l #6,%sp
+	jbra .L2
+	.even
+.L7:
+	move.w 12(%a2),%d5
+	move.l 200.w,%a0
+	move.w %d5,-(%sp)
+	move.l 600(%a0),%a0
+	jbsr (%a0)
+	move.l %a0,%d3
+	addq.l #2,%sp
+	cmp.l %d4,%a0
+	jbhi .L4
+	move.l 200.w,%a0
+	move.w %d5,-(%sp)
+	move.l 632(%a0),%a0
+	jbsr (%a0)
+	add.l %d3,%d0
+	addq.l #2,%sp
+	move.l %a2,%d1
+	cmp.l %d4,%d0
+	jbhi .L1
+.L4:
+	move.l 200.w,%a0
+	move.l 436(%a0),%a0
+	jbsr (%a0)
+	move.l %a0,%a2
+.L2:
+	cmp.w #0,%a2
+	jbne .L7
+	moveq.l #0,%d1
+.L1:
+	move.l %d1,%a0
+	movm.l (%sp)+,#0x438
+	rts

+ 7 - 0
tigcc/archive/fixbf.s

@@ -0,0 +1,7 @@
+	.xdef __fixbfsi,__fixunsbfsi
+
+.text
+__fixbfsi:
+__fixunsbfsi:
+	moveq.l #24,%d0
+	jra __fp_entry_1

+ 6 - 0
tigcc/archive/floatbf.s

@@ -0,0 +1,6 @@
+	.xdef __floatsibf
+
+.text
+__floatsibf:
+	moveq.l #28,%d0
+	jra __fp_entry

+ 85 - 0
tigcc/archive/fopen.c

@@ -0,0 +1,85 @@
+#include <stdio.h>
+#include <tigcclib.h>
+
+#define DEFAULT_FILE_ALLOC_SIZE 128
+#define DEFAULT_FILE_BUFF_INC DEFAULT_FILE_ALLOC_SIZE
+
+__ATTR_LIB_C__ FILE *fopen(const char *name, const char *mode)
+{
+  char str[50],*fpos,*epos,*base=0,*sptr=str,chmode=mode[0];
+  short bmode=(mode[1]=='b'||(mode[1]&&mode[2]=='b')),flags=0,ferr;
+  FILE *f;
+  HSym hsym;
+  HANDLE handle=H_NULL;
+  
+  *sptr=0; while((*++sptr=*name++));
+  
+  hsym=SymFind(sptr);
+  if(hsym.folder)
+    {
+      SYM_ENTRY *sym_entry=DerefSym(hsym);
+      if((sym_entry->flags.flags_n&(SF_LOCKED|SF_OPEN|SF_ARCHIVED|SF_BUSY))&&strpbrk(mode,"wa+"))
+        return NULL;
+      handle=sym_entry->handle;
+    }
+  else
+    {
+      if(chmode=='r') return NULL;
+    }
+
+  if(!(f=malloc(sizeof(FILE)))) return NULL;
+  
+  if(chmode=='r'||chmode=='a')
+    {
+      flags=_F_READ;
+      if(handle)
+        {
+          base=HLock(handle);
+          f->alloc=HeapSize(handle);
+        }
+      else
+        {
+          chmode='w';
+        }
+    }
+  
+  if(chmode=='w')
+    {
+      SCR_STATE scr_state;
+      flags=_F_WRIT;
+      SaveScrState(&scr_state);
+      hsym=SymAdd(sptr);
+      ferr=!(hsym.folder);
+      RestoreScrState(&scr_state);
+      if(!ferr)
+        {
+          handle=HeapAlloc(DEFAULT_FILE_ALLOC_SIZE);
+          ferr=!(DerefSym(hsym)->handle=handle);
+        }
+      if(ferr)
+        {
+          SymDel(sptr);
+          free(f);
+          return NULL;
+        }
+      
+      f->alloc=DEFAULT_FILE_ALLOC_SIZE;
+      
+      base=HLock(handle);
+      if(bmode) poke_w(base,0);
+      else
+        {
+          poke_l(base,0x00050001);
+          poke_l(base+4,0x2000E000);
+        }
+    }
+  
+  epos=base+peek_w(base)+(bmode?2:0);
+  if(chmode=='a') flags=_F_WRIT,fpos=epos;
+  else fpos=base+(bmode?2:5);
+  if(epos==fpos) flags|=_F_EOF;
+  if(mode[1]=='+'||mode[2]=='+') flags|=_F_RDWR;
+  if(bmode) flags|=_F_BIN;
+  f->handle=handle; f->base=base; f->flags=flags; f->fpos=fpos; f->unget=0; f->buffincrement=DEFAULT_FILE_BUFF_INC;
+  return f;
+}

+ 242 - 0
tigcc/archive/fopen.s

@@ -0,0 +1,242 @@
+	.file	"fopen.c"
+#NO_APP
+	.text
+tigcc_compiled.:
+#APP
+	.set _A_LINE,0xA000
+	.set MT_TEXT,0x8000
+	.set MT_XREF,0x9000
+	.set MT_ICON,0xA000
+	.set MT_CASCADE,0x4000
+#NO_APP
+	.section	.rodata.__unalignedstr,"dmu"
+.LC0:
+	.ascii "wa+\0"
+	.text
+	.even
+	.globl	fopen
+fopen:
+	lea (-76,%sp),%sp
+	movm.l #0x1f3e,-(%sp)
+	move.l %a1,%a6
+	sub.l %a4,%a4
+	lea (62,%sp),%a5
+	move.b (%a1),%d7
+	clr.w 42(%sp)
+	move.b 1(%a1),%d0
+	cmp.b #98,%d0
+	jbeq .L3
+	tst.b %d0
+	jbeq .L2
+	cmp.b #98,2(%a1)
+	jbne .L2
+.L3:
+	move.w #1,42(%sp)
+.L2:
+	clr.w %d6
+	clr.w %d5
+	clr.b (%a5)
+.L4:
+	addq.l #1,%a5
+	move.b (%a0)+,%d0
+	move.b %d0,(%a5)
+	jbne .L4
+#APP
+	.xdef __ref_all___set_file_in_use_bit
+#NO_APP
+	move.l 200.w,%a0
+	move.l 384(%a0),%a0
+	move.l %a5,-(%sp)
+	jbsr (%a0)
+	move.l %d0,%d4
+	clr.w %d0
+	swap %d0
+	addq.l #4,%sp
+	tst.w %d0
+	jbeq .L7
+	move.l 200.w,%a0
+	move.l %d4,-(%sp)
+	move.l 484(%a0),%a0
+	jbsr (%a0)
+	move.l %a0,%a2
+	move.w 10(%a0),%d0
+	and.w #-32232,%d0
+	addq.l #4,%sp
+	jbeq .L8
+	move.l 200.w,%a0
+	pea .LC0
+	move.l %a6,-(%sp)
+	move.l 2520(%a0),%a0
+	jbsr (%a0)
+	addq.l #8,%sp
+	moveq.l #0,%d0
+	cmp.w #0,%a0
+	jbne .L1
+.L8:
+	move.w 12(%a2),%d5
+	jbra .L9
+	.even
+.L7:
+	moveq.l #0,%d0
+	cmp.b #114,%d7
+	jbeq .L1
+.L9:
+	move.l 200.w,%a0
+	pea 20.w
+	move.l 648(%a0),%a0
+	jbsr (%a0)
+	move.l %a0,%a3
+	addq.l #4,%sp
+	moveq.l #0,%d0
+	cmp.w #0,%a0
+	jbeq .L1
+	cmp.b #114,%d7
+	jbeq .L13
+	cmp.b #97,%d7
+	jbne .L12
+.L13:
+	moveq.l #1,%d6
+	tst.w %d5
+	jbeq .L14
+	move.l 200.w,%a0
+	move.w %d5,-(%sp)
+	move.l 612(%a0),%a0
+	jbsr (%a0)
+	move.l %a0,%a4
+	move.l 200.w,%a0
+	move.w %d5,-(%sp)
+	move.l 632(%a0),%a0
+	jbsr (%a0)
+	move.l %d0,14(%a3)
+	addq.l #4,%sp
+	jbra .L12
+	.even
+.L14:
+	moveq.l #119,%d7
+.L12:
+	cmp.b #119,%d7
+	jbne .L16
+	moveq.l #2,%d6
+	move.l 200.w,%a0
+	lea (44,%sp),%a2
+	move.l %a2,-(%sp)
+	move.l 1664(%a0),%a0
+	jbsr (%a0)
+#APP
+	.xdef __ref_all___set_file_in_use_bit
+#NO_APP
+	move.l 200.w,%a0
+	move.l 368(%a0),%a0
+	move.l %a5,-(%sp)
+	jbsr (%a0)
+	move.l %d0,%d4
+	clr.w %d0
+	swap %d0
+	addq.l #8,%sp
+	tst.w %d0
+	seq %d0
+	move.b %d0,%d3
+	ext.w %d3
+	neg.w %d3
+	move.l 200.w,%a0
+	move.l %a2,-(%sp)
+	move.l 1668(%a0),%a0
+	jbsr (%a0)
+	addq.l #4,%sp
+	tst.w %d3
+	jbne .L17
+	move.l 200.w,%a0
+	pea 128.w
+	move.l 576(%a0),%a0
+	jbsr (%a0)
+	move.w %d0,%d5
+	move.l 200.w,%a0
+	move.l %d4,-(%sp)
+	move.l 484(%a0),%a0
+	jbsr (%a0)
+	move.w %d5,12(%a0)
+	addq.l #8,%sp
+	seq %d0
+	move.b %d0,%d3
+	ext.w %d3
+	neg.w %d3
+.L17:
+	move.l 200.w,%a0
+	tst.w %d3
+	jbeq .L18
+#APP
+	.xdef __ref_all___set_file_in_use_bit
+#NO_APP
+	move.l 376(%a0),%a0
+	move.l %a5,-(%sp)
+	jbsr (%a0)
+	move.l 200.w,%a0
+	move.l %a3,-(%sp)
+	move.l 652(%a0),%a0
+	jbsr (%a0)
+	moveq.l #0,%d0
+	addq.l #8,%sp
+	jbra .L1
+	.even
+.L18:
+	move.l #128,14(%a3)
+	move.w %d5,-(%sp)
+	move.l 612(%a0),%a0
+	jbsr (%a0)
+	move.l %a0,%a4
+	addq.l #2,%sp
+	tst.w 42(%sp)
+	jbeq .L19
+	clr.w (%a0)
+	jbra .L16
+	.even
+.L19:
+	move.l #327681,(%a0)
+	move.l #536928256,4(%a0)
+.L16:
+	clr.l %d0
+	move.w (%a4),%d0
+	add.l %a4,%d0
+	tst.w 42(%sp)
+	jbeq .L21
+	addq.l #2,%d0
+.L21:
+	cmp.b #97,%d7
+	jbne .L22
+	moveq.l #2,%d6
+	move.l %d0,%a0
+	jbra .L23
+	.even
+.L22:
+	lea (2,%a4),%a0
+	tst.w 42(%sp)
+	jbne .L23
+	lea (5,%a4),%a0
+.L23:
+	cmp.l %d0,%a0
+	jbne .L26
+	or.w #32,%d6
+.L26:
+	cmp.b #43,1(%a6)
+	jbeq .L28
+	cmp.b #43,2(%a6)
+	jbne .L27
+.L28:
+	or.w #3,%d6
+.L27:
+	tst.w 42(%sp)
+	jbeq .L29
+	or.w #64,%d6
+.L29:
+	move.w %d5,8(%a3)
+	move.l %a4,4(%a3)
+	move.w %d6,10(%a3)
+	move.l %a0,(%a3)
+	clr.w 12(%a3)
+	move.w #128,18(%a3)
+	move.l %a3,%d0
+.L1:
+	move.l %d0,%a0
+	movm.l (%sp)+,#0x7cf8
+	lea (76,%sp),%sp
+	rts

+ 17 - 0
tigcc/archive/fpcall.s

@@ -0,0 +1,17 @@
+	.xdef __fp_entry_1,__fp_call
+
+.text
+__fp_entry_1:
+	lea (%sp,24),%a1
+__fp_call:
+	add.w #728,%d0
+	move.l -(%a1),-(%sp)
+	move.l -(%a1),-(%sp)
+	move.l -(%a1),-(%sp)
+	move.l -(%a1),-(%sp)
+	move.l -(%a1),-(%sp)
+	move.l 0xC8,%a0
+	move.l (%a0,%d0.w),%a0
+	jsr (%a0)
+	lea (%sp,20),%sp
+	rts

+ 11 - 0
tigcc/archive/fpentry.s

@@ -0,0 +1,11 @@
+	.xdef __fp_entry
+
+.text
+__fp_entry:
+	link %a6,#-10
+	lea (%a6,28),%a1
+	jbsr __fp_call
+	movem.l (%a6,-10),%d0-%d1
+	move.w (%a6,-2),%d2
+	unlk %a6
+	rts

+ 17 - 0
tigcc/archive/fprintf.s

@@ -0,0 +1,17 @@
+| Warning: This routine has the attribute __ATTR_TIOS__!
+
+	.xdef fprintf
+
+.text
+fprintf:
+	movea.l 0xC8,%a0
+	movea.l (%a0,0x14C),%a0 /* vcbprintf */
+	lea (%a0,32),%a0
+	movea.w (%a0),%a1
+	pea (%sp,12)
+	move.l (%sp,12),-(%sp)
+	move.l (%sp,12),-(%sp)
+	pea fputc
+	jsr (%a0.l,%a1)
+	lea (%sp,16),%sp
+	rts

+ 33 - 0
tigcc/archive/fputc.c

@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <peekpoke.h>
+#include <alloc.h>
+
+__ATTR_TIOS_CALLBACK__ short fputc(short c, FILE *f)
+{
+  short tmode=!(f->flags&_F_BIN);
+  char *base=f->base,*oldbase=base;
+  if(f->flags&_F_ERR) return EOF;
+  if(!(f->flags&_F_WRIT)) __FERROR(f);
+  if(peek_w(base)+10>f->alloc)
+    {
+      HeapUnlock(f->handle);
+      if(!HeapRealloc(f->handle,f->alloc+=f->buffincrement)) __FERROR(f);
+      base=f->base=HLock(f->handle);
+      f->fpos+=base-oldbase;
+      oldbase=base;
+    }
+  if(feof(f)) (*(short*)base)++;
+  if(c=='\n'&&tmode) c='\r';
+  poke(f->fpos++,c);
+  if(c=='\r'&&tmode) fputc(' ',f);
+  if(base+peek_w(base)+(tmode?0:2)==f->fpos)
+    {
+      f->flags|=_F_EOF;
+      if(tmode)
+        {
+          poke(f->fpos,0);
+          poke(f->fpos+1,0xE0);
+        }
+    }
+  return c;
+}

+ 116 - 0
tigcc/archive/fputc.s

@@ -0,0 +1,116 @@
+	.file	"fputc.c"
+#NO_APP
+	.text
+tigcc_compiled.:
+#APP
+	.set _A_LINE,0xA000
+#NO_APP
+	.text
+	.even
+	.globl	fputc
+fputc:
+	movm.l #0x1c30,-(%sp)
+	move.w 24(%sp),%d4
+	move.l 26(%sp),%a3
+	move.w 10(%a3),%d1
+	move.w %d1,%d3
+	lsr.w #6,%d3
+	eor.w #1,%d3
+	and.w #1,%d3
+	move.l 4(%a3),%a2
+	move.l %a2,%d5
+	move.w %d1,%d0
+	and.w #16,%d0
+	moveq.l #-1,%d2
+	tst.w %d0
+	jbne .L1
+	move.w %d1,%d0
+	and.w #2,%d0
+	jbne .L3
+	or.w #16,%d1
+	move.w %d1,10(%a3)
+	jbra .L1
+	.even
+.L3:
+	move.w (%a2),%d0
+	add.w #10,%d0
+	and.l #0xFFFF,%d0
+	cmp.l 14(%a3),%d0
+	jbls .L4
+	move.l 200.w,%a0
+	move.w 8(%a3),-(%sp)
+	move.l 636(%a0),%a0
+	jbsr (%a0)
+	move.l 200.w,%a0
+	clr.l %d0
+	move.w 18(%a3),%d0
+	add.l 14(%a3),%d0
+	move.l %d0,14(%a3)
+	move.l %d0,-(%sp)
+	move.w 8(%a3),-(%sp)
+	move.l 628(%a0),%a0
+	jbsr (%a0)
+	addq.l #8,%sp
+	tst.w %d0
+	jbne .L5
+	or.w #16,10(%a3)
+	moveq.l #-1,%d2
+	jbra .L1
+	.even
+.L5:
+	move.l 200.w,%a0
+	move.w 8(%a3),-(%sp)
+	move.l 612(%a0),%a0
+	jbsr (%a0)
+	move.l %a0,4(%a3)
+	move.l %a0,%a2
+	move.l %a0,%d0
+	sub.l %d5,%d0
+	add.l %d0,(%a3)
+	addq.l #2,%sp
+.L4:
+	move.w 10(%a3),%d0
+	and.w #32,%d0
+	jbeq .L6
+	addq.w #1,(%a2)
+.L6:
+	cmp.w #10,%d4
+	jbne .L7
+	tst.w %d3
+	jbeq .L7
+	moveq.l #13,%d4
+.L7:
+	move.l (%a3),%a0
+	move.b %d4,(%a0)
+	addq.l #1,(%a3)
+	cmp.w #13,%d4
+	jbne .L8
+	tst.w %d3
+	jbeq .L8
+	move.l %a3,-(%sp)
+	move.w #32,-(%sp)
+	jbsr fputc
+	addq.l #6,%sp
+.L8:
+	clr.l %d0
+	move.w (%a2),%d0
+	add.l %a2,%d0
+	move.l (%a3),%a1
+	tst.w %d3
+	jbne .L11
+	addq.l #2,%d0
+.L11:
+	cmp.l %d0,%a1
+	jbne .L10
+	or.w #32,10(%a3)
+	tst.w %d3
+	jbeq .L10
+	clr.b (%a1)
+	move.l (%a3),%a0
+	move.b #-32,1(%a0)
+.L10:
+	move.w %d4,%d2
+.L1:
+	move.w %d2,%d0
+	movm.l (%sp)+,#0xc38
+	rts

+ 70 - 0
tigcc/archive/fputchar.s

@@ -0,0 +1,70 @@
+| Warning: This routine has the attribute __ATTR_TIOS_CALLBACK__!
+
+	.xdef fputchar
+
+.text
+fputchar:
+	link.w %a6,#-20
+	movem.l %d3-%d7/%a2-%a5,-(%sp)
+	clr.w %d6
+	move.b (%a6,9),%d6
+	move.l 0xC8,%a5
+	move.l (%a5,1592),%a0 /* FontGetSys */
+	jsr (%a0)
+	ext.w %d0 /* Yes, I know we technically shouldn't sign-extend an
+	             unsigned char, but it is always positive anyway. */
+	move.w %d0,%d4
+	lsl.w #1,%d4
+	addq.w #6,%d4
+	move.l (%a5,188),%a3 /* ScrRect */
+	pea (%a6,-18)
+	move.l (%a5,1664),%a0 /* SaveScrState */
+	jsr (%a0)
+	move.w (%a6,-8),%d5
+	move.w (%a6,-6),%d3
+	move.w %d6,-(%sp)
+	move.l (%a5,1600),%a0 /* FontCharWidth */
+	jsr (%a0)
+	move.w %d0,%d7
+	cmp.b #10,%d6
+	jbeq .L__fputchar_1
+	move.w %d5,%d0
+	add.w %d7,%d0
+	clr.w %d1
+	move.b (%a3,2),%d1
+	cmp.w %d0,%d1
+	jbge .L__fputchar_2
+.L__fputchar_1:
+	clr.w %d5
+	add.w %d4,%d3
+.L__fputchar_2:
+	move.w %d3,%d0
+	add.w %d4,%d0
+	clr.w %d1
+	move.b (%a3,3),%d1
+	cmp.w %d0,%d1
+	jbge .L__fputchar_3
+	clr.w (%sp)
+	move.w %d4,-(%sp)
+	move.l %a3,-(%sp)
+	move.l %a3,-(%sp)
+	move.l (%a5,1580),%a0 /* ScrRectScroll */
+	jsr (%a0)
+	sub.w %d4,%d3
+.L__fputchar_3:
+	move.w #4,(%sp)
+	move.w %d6,-(%sp)
+	move.w %d3,-(%sp)
+	move.w %d5,-(%sp)
+	cmp.b #10,%d6
+	jbeq .L__fputchar_4
+	move.l (%a5,1680),%a0 /* DrawChar */
+	jsr (%a0)
+	add.w %d7,(%sp)
+.L__fputchar_4:
+	move.l (%a5,1652),%a0 /* MoveTo */
+	jsr (%a0)
+	move.w %d6,%d0
+	movm.l -56(%a6),%d3-%d7/%a2-%a5
+	unlk %a6
+	rts

+ 15 - 0
tigcc/archive/fputs.s

@@ -0,0 +1,15 @@
+	.xdef fputs
+
+.text
+.L__fputs_1:
+	move.l %a0,(%sp,4)
+	move.l (%sp,8),-(%sp)
+	move.w %d1,-(%sp)
+	jbsr fputc
+	addq.l #6,%sp
+fputs:
+	move.l (%sp,4),%a0
+	clr.w %d1
+	move.b (%a0)+,%d1
+	jbne .L__fputs_1
+	rts

+ 17 - 0
tigcc/archive/fread.c

@@ -0,0 +1,17 @@
+#include <stdio.h>
+
+__ATTR_LIB_C__ unsigned short fread(void *ptr, short size, short n, FILE *f)
+{
+  unsigned short i,j;
+  short c,binmode=f->flags&_F_BIN;
+  f->flags|=_F_BIN;
+  for(i=0;i<(unsigned short)n;i++)
+    for(j=0;j<(unsigned short)size;j++)
+      {
+        if((c=fgetc(f))<0) goto fread_error;
+        *(unsigned char*)ptr++=c;
+      }
+fread_error:
+  f->flags&=binmode|(~_F_BIN);
+  return i;
+}

+ 45 - 0
tigcc/archive/fread.s

@@ -0,0 +1,45 @@
+	.file	"fread.c"
+#NO_APP
+	.text
+tigcc_compiled.:
+#APP
+	.set _A_LINE,0xA000
+#NO_APP
+	.text
+	.even
+	.globl	fread
+fread:
+	movm.l #0x1f30,-(%sp)
+	move.l %a0,%a3
+	move.w %d0,%d7
+	move.w %d1,%d6
+	move.l %a1,%a2
+	move.w 10(%a1),%d0
+	move.w %d0,%d4
+	and.w #64,%d4
+	or.w #64,%d0
+	move.w %d0,10(%a1)
+	clr.w %d5
+	jbra .L2
+	.even
+.L12:
+	move.l %a2,%a0
+	jbsr fgetc
+	tst.w %d0
+	jblt .L11
+	move.b %d0,(%a3)+
+	addq.w #1,%d3
+.L6:
+	cmp.w %d3,%d7
+	jbhi .L12
+	addq.w #1,%d5
+.L2:
+	clr.w %d3
+	cmp.w %d5,%d6
+	jbhi .L6
+.L11:
+	or.w #-65,%d4
+	and.w %d4,10(%a2)
+	move.w %d5,%d0
+	movm.l (%sp)+,#0xcf8
+	rts

+ 25 - 0
tigcc/archive/freetimer.s

@@ -0,0 +1,25 @@
+	.xdef OSVFreeTimer
+
+.text
+OSVFreeTimer:
+	subq.w #1,%d0
+	cmpi.w #2,%d0
+	bcc.s .L__timer_ffai
+	muls.w #12,%d0
+	move.l 0x74,%a0
+	cmp.l #132133782,(%a0,-4)
+	bne.s .L__timer_fok
+	move.l #-1,-32(%a0,%d0.w)
+	move.l (%a0,-32),%d0
+	and.l (%a0,-20),%d0
+	addq.l #1,%d0
+	bne.s .L__timer_fok
+	bclr.b #2,0x600001
+	move.l (%a0,-8),0x74:w
+	bset.b #2,0x600001
+.L__timer_fok:
+	moveq #1,%d0
+	rts
+.L__timer_ffai:
+	clr.w %d0
+	rts

+ 22 - 0
tigcc/archive/fscanf.s

@@ -0,0 +1,22 @@
+|fscanf() implementation for TIGCCLIB - callback functions
+|Copyright (C) Kevin Kofler, 2002-2003
+
+/*Prototypes:
+  CALLBACK short __fscanf_get(FILE *param);
+  CALLBACK void __fscanf_unget(short c, FILE *param);
+  */
+
+.text
+.xdef __fscanf_get
+__fscanf_get:
+|extern short fgetc(FILE*)__ATTR_LIB_C__;
+move.l 4(%a7),%a0
+jmp fgetc
+
+.xdef __fscanf_unget
+__fscanf_unget:
+|#define ungetc(c,f) ((f)->unget=((c)|0x8000))
+bset.b #7,4(%a7)
+movea.l 6(%a7),%a0
+move.l 4(%a7),12(%a0)
+rts

+ 17 - 0
tigcc/archive/fseek.c

@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <peekpoke.h>
+
+__ATTR_LIB_C__ short fseek(FILE *f, long offset, short wh)
+{
+  short bmode=f->flags&_F_BIN;
+  char *start=(char*)f->base+(bmode?2:5);
+  char *end=(char*)f->base+peek_w(f->base)+(bmode?2:0);
+  char *pos=((wh==SEEK_SET)?start:((wh==SEEK_CUR)?(f->fpos):end))+offset;
+  if(f->flags&_F_ERR) return EOF;
+  if(pos<start||pos>end||(unsigned short)wh>SEEK_END) __FERROR(f);
+  f->fpos=pos;
+  f->unget=0;
+  if(pos==end) f->flags|=_F_EOF;
+  else f->flags&=~_F_EOF;
+  return 0;
+}

+ 74 - 0
tigcc/archive/fseek.s

@@ -0,0 +1,74 @@
+	.file	"fseek.c"
+#NO_APP
+	.text
+tigcc_compiled.:
+#APP
+	.set _A_LINE,0xA000
+#NO_APP
+	.text
+	.even
+	.globl	fseek
+fseek:
+	movm.l #0x1820,-(%sp)
+	move.l %d0,%d3
+	move.w %d1,%d4
+	move.w 10(%a0),%d1
+	move.w %d1,%d2
+	and.w #64,%d2
+	move.l 4(%a0),%a1
+	lea (2,%a1),%a2
+	jbne .L3
+	lea (5,%a1),%a2
+.L3:
+	clr.l %d0
+	move.w (%a1),%d0
+	add.l %d0,%a1
+	tst.w %d2
+	jbeq .L4
+	addq.l #2,%a1
+.L4:
+	move.l %a2,%d2
+	add.l %d3,%d2
+	tst.w %d4
+	jbeq .L6
+	move.l %a1,%d2
+	add.l %d3,%d2
+	cmp.w #1,%d4
+	jbne .L6
+	move.l (%a0),%d2
+	add.l %d3,%d2
+.L6:
+	move.w %d1,%d0
+	and.w #16,%d0
+	moveq.l #-1,%d3
+	tst.w %d0
+	jbne .L1
+	cmp.l %d2,%a2
+	jbhi .L11
+	cmp.l %d2,%a1
+	jbcs .L11
+	cmp.w #2,%d4
+	jbls .L10
+.L11:
+	or.w #16,%d1
+	move.w %d1,10(%a0)
+	moveq.l #-1,%d3
+	jbra .L1
+	.even
+.L10:
+	move.l %d2,(%a0)
+	clr.w 12(%a0)
+	cmp.l %d2,%a1
+	jbne .L12
+	or.w #32,%d1
+	jbra .L14
+	.even
+.L12:
+	and.w #-33,%d1
+.L14:
+	move.w %d1,10(%a0)
+	clr.w %d3
+.L1:
+	move.w %d3,%d0
+	movm.l (%sp)+,#0x418
+	rts

+ 7 - 0
tigcc/archive/fsetbufsize.c

@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+__ATTR_LIB_C__ void fsetbufsize(short newsize, FILE *f)
+{
+  if(newsize&&f)
+    f->buffincrement=newsize;
+}

+ 19 - 0
tigcc/archive/fsetbufsize.s

@@ -0,0 +1,19 @@
+	.file	"fsetbufsize.c"
+#NO_APP
+	.text
+tigcc_compiled.:
+#APP
+	.set _A_LINE,0xA000
+#NO_APP
+	.text
+	.even
+	.globl	fsetbufsize
+fsetbufsize:
+	tst.w %d0
+	jbeq .L1
+	cmp.w #0,%a0
+	jbeq .L1
+	move.w %d0,18(%a0)
+.L1:
+	rts
+	nop

+ 7 - 0
tigcc/archive/ftell.c

@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+__ATTR_LIB_C__ long ftell(const FILE *f)
+{
+  if(f->flags&_F_ERR) return EOF;
+  return f->fpos-(char*)f->base-((f->flags&_F_BIN)?2:5);
+}

+ 34 - 0
tigcc/archive/ftell.s

@@ -0,0 +1,34 @@
+	.file	"ftell.c"
+#NO_APP
+	.text
+tigcc_compiled.:
+#APP
+	.set _A_LINE,0xA000
+#NO_APP
+	.text
+	.even
+	.globl	ftell
+ftell:
+	move.w 10(%a0),%d1
+	move.w %d1,%d0
+	and.w #16,%d0
+	moveq.l #-1,%d2
+	tst.w %d0
+	jbne .L1
+	and.w #64,%d1
+	move.l (%a0),%d0
+	move.l 4(%a0),%d2
+	tst.w %d1
+	jbeq .L3
+	sub.l %d2,%d0
+	subq.l #2,%d0
+	jbra .L4
+	.even
+.L3:
+	sub.l %d2,%d0
+	subq.l #5,%d0
+.L4:
+	move.l %d0,%d2
+.L1:
+	move.l %d2,%d0
+	rts

+ 14 - 0
tigcc/archive/fwrite.c

@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+__ATTR_LIB_C__ unsigned short fwrite(const void *ptr, short size, short n, FILE *f)
+{
+  unsigned short i,j;
+  short binmode=f->flags&_F_BIN;
+  f->flags|=_F_BIN;
+  for(i=0;i<(unsigned short)n;i++)
+    for(j=0;j<(unsigned short)size;j++)
+      if(fputc(*(unsigned char*)ptr++,f)<0) goto fwrite_error;
+fwrite_error:
+  f->flags&=binmode|(~_F_BIN);
+  return i;
+}

+ 48 - 0
tigcc/archive/fwrite.s

@@ -0,0 +1,48 @@
+	.file	"fwrite.c"
+#NO_APP
+	.text
+tigcc_compiled.:
+#APP
+	.set _A_LINE,0xA000
+#NO_APP
+	.text
+	.even
+	.globl	fwrite
+fwrite:
+	movm.l #0x1f30,-(%sp)
+	move.l %a0,%a3
+	move.w %d0,%d7
+	move.w %d1,%d6
+	move.l %a1,%a2
+	move.w 10(%a1),%d0
+	move.w %d0,%d4
+	and.w #64,%d4
+	or.w #64,%d0
+	move.w %d0,10(%a1)
+	clr.w %d5
+	jbra .L2
+	.even
+.L12:
+	move.l %a2,-(%sp)
+	clr.w %d0
+	move.b (%a3)+,%d0
+	move.w %d0,-(%sp)
+	jbsr fputc
+	addq.l #6,%sp
+	tst.w %d0
+	jblt .L11
+	addq.w #1,%d3
+.L6:
+	cmp.w %d3,%d7
+	jbhi .L12
+	addq.w #1,%d5
+.L2:
+	clr.w %d3
+	cmp.w %d5,%d6
+	jbhi .L6
+.L11:
+	or.w #-65,%d4
+	and.w %d4,10(%a2)
+	move.w %d5,%d0
+	movm.l (%sp)+,#0xcf8
+	rts

+ 54 - 0
tigcc/archive/getappid.s

@@ -0,0 +1,54 @@
+	.xdef EV_getAppID
+
+.text
+EV_getAppID:
+	movem.l %d3/%a2-%a3,-(%sp)
+	lea .L__appid_tb(%pc),%a2
+	moveq.l #9,%d3
+	move.l 0xC8,%a3
+	cmp.l #1000,-4(%a3)
+	jbls .L__appid_lp
+	move.l %a0,-(%sp)
+	move.l 4432(%a3),%a0 /* TIOS_EV_getAppID */
+	jsr (%a0)
+	addq.l #4,%sp
+	tst.w %d0
+	jbne .L__appid_end
+	moveq.l #-1,%d0
+	jbra .L__appid_end
+.L__appid_lp:
+	move.l %a2,-(%sp)
+	move.l %a0,-(%sp)
+	move.l 2500(%a3),%a0 /* strcmp */
+	jsr (%a0)
+	addq.l #8,%sp
+	tst.w %d0
+	jbeq .L__appid_fnd
+.L__appid_skp:
+	tst.b (%a2)+
+	dbne %d3,.L__appid_lp
+	jbne .L__appid_skp
+.L__appid_fnd:
+	move.w %d3,%d0
+	move.l %a3,%d1
+	and.l #0xE00000,%d1
+	cmp.l #0x400000,%d1
+	jbne .L__appid_end
+	cmp.w #6,%d0
+	jble .L__appid_end
+	addq.w #1,%d0
+.L__appid_end:
+	movem.l (%sp)+,%d3/%a2-%a3
+	rts
+	.even
+.L__appid_tb:
+	.asciz "TISLFTST"
+	.asciz "TIINSLVR"
+	.asciz "TITEXTED"
+	.asciz "TIPRGMED"
+	.asciz "TIDMED"
+	.asciz "TITABLED"
+	.asciz "TIGRAPH"
+	.asciz "TIWINDED"
+	.asciz "TIEQUED"
+	.asciz "TIHOME"

+ 72 - 0
tigcc/archive/gets.s

@@ -0,0 +1,72 @@
+|improved gets() implementation for TIGCCLIB
+|Copyright (C) Kevin Kofler, 2002-2003
+
+/* Prototype:
+   char *gets(char *string asm("a2")); */
+
+.equ __SaveScrState,0x1a0 /* SaveScrState */
+.equ __MoveTo,0x19d       /* MoveTo */
+
+.text
+.xdef gets
+gets:
+movem.l %a3-%a5,-(%a7)
+|SaveScrState(&ss);
+link.w %a6,#-18
+pea.l (%a7)
+move.l 0xc8:w,%a3
+move.l __SaveScrState*4(%a3),%a0
+jsr (%a0)
+|fputchar('_');
+move.w #'_',(%a7)
+jbsr fputchar
+move.l %a2,%a4 |current string pointer
+clr.b (%a4) | null-terminate the string
+move.l __MoveTo*4(%a3),%a5 |prepare MoveTo for repeated calling
+lea.l printf,%a3 |prepare printf for repeated calling
+1:
+jbsr __fgetchar
+cmp.w #13,%d0 |KEY_ENTER
+beq.s 0f
+cmp.w #257,%d0 |KEY_BACKSPACE
+bne.s 2f
+cmp.l %a4,%a2
+beq.s 1b |don't go back if we are already at the first char
+clr.b -(%a4) |delete the last character and null-terminate the string
+bra.s 3f
+2:
+move.b %d0,(%a4)+ |store the character
+clr.b (%a4) |null-terminate the string
+3: |output the changed string
+|MoveTo(ss.CurX,ss.CurY);
+move.l -8(%a6),(%a7)
+jsr (%a5)
+|printf("%s_  ",string);
+move.l %a2,(%a7)
+pea.l L.format1(%pc)
+jsr (%a3)
+addq.l #4,%a7 |cleanup the stack (we don't want our loop to overflow it)
+bra.s 1b |next character
+0: |output the final string
+|MoveTo(ss.CurX,ss.CurY);
+move.l -8(%a6),(%a7)
+jsr (%a5)
+|printf("%s  ",string);
+move.l %a2,(%a7)
+pea.l L.format2(%pc)
+jsr (%a3)
+|MoveTo(ss.CurX,ss.CurY);
+move.l -8(%a6),(%a7)
+jsr (%a5)
+|printf("%s",string);
+move.l %a2,(%a7)
+pea.l L.format3(%pc)
+jsr (%a3)
+unlk %a6
+movem.l (%a7)+,%a3-%a5
+movea.l %a2,%a0 |return the string
+rts
+
+L.format1: .asciz "%s_  "
+L.format2: .asciz "%s  "
+L.format3: .asciz "%s"

+ 76 - 0
tigcc/archive/getsn.s

@@ -0,0 +1,76 @@
+|getsn() (gets() with maximum size) implementation for TIGCCLIB
+|Copyright (C) Kevin Kofler, 2002-2003
+
+/* Prototype:
+   char *getsn(char *string asm("a2"), unsigned long maxlen asm("d3")); */
+
+.equ __SaveScrState,0x1a0 /* SaveScrState */
+.equ __MoveTo,0x19d       /* MoveTo */
+
+.text
+.xdef getsn
+getsn:
+movem.l %a3-%a5,-(%a7)
+|SaveScrState(&ss);
+link.w %a6,#-18
+pea.l (%a7)
+move.l 0xc8:w,%a3
+move.l __SaveScrState*4(%a3),%a0
+jsr (%a0)
+|fputchar('_');
+move.w #'_',(%a7)
+jbsr fputchar
+move.l %a2,%a4 |current string pointer
+clr.b (%a4) | null-terminate the string
+move.l __MoveTo*4(%a3),%a5 |prepare MoveTo for repeated calling
+lea.l printf,%a3 |prepare printf for repeated calling
+1:
+jbsr __fgetchar
+cmp.w #13,%d0 |KEY_ENTER
+beq.s 0f
+cmp.w #257,%d0 |KEY_BACKSPACE
+bne.s 2f
+cmp.l %a4,%a2
+beq.s 1b |don't go back if we are already at the first char
+clr.b -(%a4) |delete the last character and null-terminate the string
+bra.s 3f
+2:
+|if (current_pointer>=string+maxlen-1), refuse additional input
+lea.l -1(%a2,%d3:l),%a0
+cmpa.l %a0,%a4
+bcc.s 1b
+move.b %d0,(%a4)+ |store the character
+clr.b (%a4) |null-terminate the string
+3: |output the changed string
+|MoveTo(ss.CurX,ss.CurY);
+move.l -8(%a6),(%a7)
+jsr (%a5)
+|printf("%s_  ",string);
+move.l %a2,(%a7)
+pea.l L.format1(%pc)
+jsr (%a3)
+addq.l #4,%a7 |cleanup the stack (we don't want our loop to overflow it)
+bra.s 1b |next character
+0: |output the final string
+|MoveTo(ss.CurX,ss.CurY);
+move.l -8(%a6),(%a7)
+jsr (%a5)
+|printf("%s  ",string);
+move.l %a2,(%a7)
+pea.l L.format2(%pc)
+jsr (%a3)
+|MoveTo(ss.CurX,ss.CurY);
+move.l -8(%a6),(%a7)
+jsr (%a5)
+|printf("%s",string);
+move.l %a2,(%a7)
+pea.l L.format3(%pc)
+jsr (%a3)
+unlk %a6
+movem.l (%a7)+,%a3-%a5
+movea.l %a2,%a0 |return the string
+rts
+
+L.format1: .asciz "%s_  "
+L.format2: .asciz "%s  "
+L.format3: .asciz "%s"

+ 660 - 0
tigcc/archive/gray.s

@@ -0,0 +1,660 @@
+|******************************************************************************
+|
+| project name:    GrayScale-Support for TIGCC
+| author:          thomas.nussbaumer@gmx.net
+|                  Julien Muchembled (original implementation for UniversalOS)
+|
+|
+| compatible with HW1/HW2 on all AMS versions up to 2.05
+|
+|
+| $Id: gray.s,v 1.1.1.1 2004-12-22 22:49:27 kevinkofler Exp $
+|******************************************************************************
+
+|------------------------------------------------------------------------------
+| uncomment the following global to simulate HW2 on the VTI
+| (this will not use port 70001D, therefore it flickers extremely; additionally
+|  the complete HW detection is bypassed and always reports HW2)
+|------------------------------------------------------------------------------
+|.globl ALWAYS_HW2_TESTING
+
+
+	.xdef GrayOn,GrayOff,__D_plane,__L_plane,__gray_handle,__gray_hw_type
+	.xdef __switch_cnt,__gray_old_int1_hw1,__gray_old_int1_hw2
+	.xdef __gray_sync_n_count,__gray_plane_index
+	.xdef __gray_dbl_offset,__L_plane2,__D_plane2
+
+.even
+|==============================================================================
+| EXPORTED: GrayOn function (turn grayscales on) - trashes d1/a0/a1
+|==============================================================================
+GrayOn:
+	movem.l  %d2-%d7/%a2-%a6,-(%a7)
+	lea      (__switch_cnt,%pc),%a0       | reset plane switch counter to 0
+	move.l   #0,(%a0)
+	bsr.s    __gray_check_hw_version      | evaluate HW version and store it
+	lea      (__gray_hw_type,%pc),%a0
+	move.w   %d0,(%a0)
+	bsr      __gray_init_mem              | allocate and initialize memory
+	movem.l  (%a7)+,%d2-%d7/%a2-%a6
+	move.w   (__gray_handle,%pc),%d0
+	bne      __gray_init_handler          | jump to interrupt handler setup if
+	                                      | memory was allocated correctly
+	moveq    #0x0,%d0                     | otherwise return 0 (GrayOn failed)
+	rts
+|==============================================================================
+| checks for HW version (VTI is treated as HW1, because port 0x70001D is not
+|                        emulated by the VTI and this would cause NEVER switch
+|                        planes behaviour if we would use the HW2 support)
+|
+| returns 0 in d0.w for HW1 and 1 for HW2
+|
+| IMPORTANT NOTE: This function patches 2 locations in the code of the
+|                 grayscale support depending on the HW version. Patching the
+|                 locations for both types IS necessary, because if a program
+|                 is transfered from one calc to another one the default values
+|                 got already overwritten (if program was not archived)
+|==============================================================================
+__gray_check_hw_version:
+.ifdef ALWAYS_HW2_TESTING
+	bra.s __always_hw2_proceed
+.endif
+	move.l   0xc8,%d0
+	and.l    #0xE00000,%d0          | get the ROM base
+	move.l   %d0,%a0
+	moveq    #0,%d0
+	move.l   260(%a0),%a1           | get pointer to the hardware param block
+	add.l    #0x10000,%a0
+	cmp.l    %a0,%a1                | check if the HW parameter block is near
+	bcc.s    __gray_patches_for_hw1 | if it is too far, it is HW1
+	cmp.w    #22,(%a1)              | check if the parameter block contains HW
+	bls.s    __gray_patches_for_hw1 | if it is too small, it is HW1
+	cmp.l    #1,22(%a1)             | check the hardware version
+	beq.s    __gray_patches_for_hw1 | if not 1, it is HW2 (or an unknown HW)
+    |--------------------------------------------------------------------------
+    | check for VTI (trick suggested by Julien Muchembled)
+    |--------------------------------------------------------------------------
+	trap     #12         | enter supervisor mode. returns old (%sr) in %d0.w
+	move.w   #0x3000,%sr | set a non-existing flag in %sr (but keep s-flag)
+	swap     %d0         | save %d0.w content in upper part of %d0
+	move.w   %sr,%d0     | get %sr content and check for non-existing flag
+	btst     #12,%d0     | this non-existing flag can only be set on the VTI
+	beq.s    __gray_hw2type_detected  | flag not set -> no VTI
+    |--------------------------------------------------------------------------
+    | HW1 detected
+    |--------------------------------------------------------------------------
+	swap     %d0          | restore old %sr content and return 0
+	move.w   %d0,%sr
+	moveq    #0,%d0
+    |--------------------------------------------------------------------------
+    | patches code for HW1 version
+    |
+    | necessary memory == 1 plane + 8 Bytes == 3848
+    |
+    | the additionally 8 bytes are necessary for rounding later to a multiple
+    | of 8
+    |--------------------------------------------------------------------------
+__gray_patches_for_hw1:
+	lea (__gray_size_to_allocate,%pc),%a0
+	move.w #0x0f08,(%a0)
+	move.w #0,(__gray_size_to_add-__gray_size_to_allocate,%a0)
+	rts
+    |--------------------------------------------------------------------------
+    | HW2 detected
+    |--------------------------------------------------------------------------
+__gray_hw2type_detected:
+	swap     %d0         | restore old %sr content and set return to 1
+	move.w   %d0,%sr
+.ifdef ALWAYS_HW2_TESTING
+__always_hw2_proceed:
+.endif
+	moveq    #1,%d0
+    |--------------------------------------------------------------------------
+    | patches code for HW2 version
+    |
+    | necessary memory == 2 planes + 8 Bytes == 7688
+    |
+    | the additionally 8 bytes are necessary for rounding later to a multiple
+    | of 8
+    |--------------------------------------------------------------------------
+	lea      (__gray_size_to_allocate,%pc),%a0
+	move.w   #0x1e08,(%a0)
+	move.w   #0xf00,(__gray_size_to_add - __gray_size_to_allocate,%a0)
+	rts
+__gray_hw_type:    | stores HW type (0==HW1 or VTI  1==HW2)
+	.word 0
+|==============================================================================
+| Interrupt 1 handler for HW1
+|==============================================================================
+__gray_int1_handler_hw1:
+	movem.l  %d0/%a0,-(%a7)
+    |--------------------------------------------------------------------------
+    | Load skip counter and increment it (count = (count+1)&0x3). Skip any
+    | further operation if count is 1, 2 or 3. This means that every 4th call
+    | of the INT1 handler is a candidate for a plane switch
+    |--------------------------------------------------------------------------
+	lea      (__gray_skipcount,%pc),%a0
+	addq.b   #1,(%a0)
+	andi.b   #0x3,(%a0)+            | IMPORTANT: a0 points now to __gray_phase!
+	bne.s    __gray_proceed_old
+    |--------------------------------------------------------------------------
+    | to evaluate which plane we use counter __gray_phase. This counter
+    | performs the following counting 8->4->0->8.
+    | 0 will use D_plane pointer
+    | 4 will use L_plane pointer
+    | (8 will be skipped, so it stays at D_plane)
+    |--------------------------------------------------------------------------
+	move.w   (%a0),%d0
+	subq.w   #4,%d0                  | subtract 4 from phase counter
+	bcc.s    __gray_store            | not negative -> don't reset
+	moveq    #0x8,%d0                | reset phase counter to 8
+__gray_store:
+	move.w   %d0,(%a0)               | store new phase counter value
+	cmp.b    #8,%d0
+	beq.s    __gray_proceed_old      | for value 8 we do nothing (dark plane
+	                                 | stays active)
+	lea (__D_plane,%pc),%a0
+    |--------------------------------------------------------------------------
+    | doublebuffer extension ... add content of __gray_dbl_offset to %d0
+    |--------------------------------------------------------------------------
+	add.w  (__gray_dbl_offset-__D_plane,%a0),%d0
+	suba.w %d0,%a0
+	move.l   (%a0),%d0               | load the address of this plane
+	lsr.l    #3,%d0                  | reduce to address / 8
+	move.w   %d0,0x600010            | set new plane startaddress
+	lea      (__switch_cnt,%pc),%a0  | increment switch count
+	addq.l   #1,(%a0)
+__gray_proceed_old:
+	movem.l  (%a7)+,%d0/%a0
+    |--------------------------------------------------------------------------
+    |  JUMP to previous installed interrupt handler
+    |--------------------------------------------------------------------------
+	.word    0x4ef9                  | "JMP address" opcode
+__gray_old_int1_hw1:
+	.long    0x00000000              | address of old int1 gots stored here
+__gray_dummy1:                           | NOT used yet (just for alignment)
+	.byte    0x00
+|------------------------------------------------------------------------------
+| __gray_skipcount is a one byte counter which performs the following counting:
+| 3 -> 0 -> 1 -> 2 -> 3
+|------------------------------------------------------------------------------
+__gray_skipcount:
+	.byte    0x03
+__gray_phase:
+	.word    0x04                    | performs: 4->0->8->4
+__switch_cnt:
+	.long    0x00000000
+|==============================================================================
+| INTERNAL: allocates memory
+|
+| modifies: __gray_handle
+|           __gray_used_mem
+|           __L_plane
+|
+| Note: __D_plane will not be changed by this function! (will be set by
+|                                                        __gray_init_handler)
+|==============================================================================
+__gray_init_mem:
+	lea      (__gray_handle,%pc),%a5            | if __gray_handle is not 0
+	tst.w    (%a5)                              | we have already allocated
+	bne.s    __gray_init_return                 | memory -> out here
+    |--------------------------------------------------------------------------
+    | HeapAllocHigh(HW1=3848 bytes or HW2=7688 bytes)
+    |--------------------------------------------------------------------------
+	movea.l  0xc8,%a0
+	lea      (0x92*4,%a0),%a0 /* HeapAllocHigh */
+	.word    0x4878                       | opcode of "PEA #value"
+__gray_size_to_allocate:                      | the size gets patched !!
+	.word    0x1e08
+	movea.l  (%a0),%a2
+	jsr      (%a2)
+	addq.w   #4,%a7
+	move.w   %d0,(%a5)+                   | store handle in handle variable
+	beq.s    __gray_init_return           | alloc failed (handle=0) -> out here
+	clr.w    (%a5)                        | clears __gray_dbl_offset
+    |--------------------------------------------------------------------------
+    | HeapDeref(__gray_handle)
+    |--------------------------------------------------------------------------
+	move.w   %d0,-(%a7)
+	movea.l  0xc8,%a0
+	lea      (0x96*4,%a0),%a0 /* HeapDeref */
+	movea.l  (%a0),%a2
+	jsr      (%a2)
+	addq.l   #2,%a7
+    |--------------------------------------------------------------------------
+    | align memory address to next 8-byte boundary and store address in
+    | __gray_used_mem
+    |
+    | for HW1: __L_plane gets set to the same address as __gray_used_mem
+    | for HW2: __L_plane gets set to __gray_used_mem + 0xf00
+    |--------------------------------------------------------------------------
+	move.l   %a0,%d0
+	addq.l   #7,%d0
+	andi.b   #0xF8,%d0
+	lea      (__gray_used_mem,%pc),%a0
+	move.l   %d0,(%a0)
+	.word    0x0680              | opcode of "ADDI.L #value,%a0"
+	.word    0x0000
+__gray_size_to_add:
+	.word    0x0F00              | gets patched (HW1:0 HW2:0x0f00)
+	move.l   %d0,(__L_plane - __gray_used_mem,%a0)
+__gray_init_return:
+	rts
+
+|------------------------------------------------------------------------------
+| handle to allocated memory used by grayscale
+|------------------------------------------------------------------------------
+__gray_handle:
+	.word    0
+
+|------------------------------------------------------------------------------
+| DOUBLEBUFFER extension
+|------------------------------------------------------------------------------
+__gray_dbl_offset: | has to be directly AFTER __gray_handle!!
+	.word    0
+__L_plane2:
+	.long    0x0
+__D_plane2:
+	.long    0x0
+
+|------------------------------------------------------------------------------
+| pointer to light plane
+| HW1: same as __gray_used_mem
+| HW2: __gray_used_mem + 0xf00
+|------------------------------------------------------------------------------
+__L_plane:
+	.long    0x00004c00
+|------------------------------------------------------------------------------
+| pointer to dark plane (set by __gray_init_handler)
+| HW1: 0x4c00
+| HW2: same as __gray_used_mem
+|------------------------------------------------------------------------------
+__D_plane:
+	.long    0x00004c00
+|------------------------------------------------------------------------------
+| pointer to allocated memory ALIGNED to 8-byte boundary
+|------------------------------------------------------------------------------
+__gray_used_mem:
+	.long    0x00004c00
+|------------------------------------------------------------------------------
+| This variable is very hard to describe. Indeed this isn't one variable,
+| but two variables combined in one.
+|
+| Description will be added later ....
+|------------------------------------------------------------------------------
+__gray_sync_n_count:
+	.word    0x0000
+|------------------------------------------------------------------------------
+| holds the index of the plane which should be drawn next (NOTE: this label
+| is never addressed directly, but indirectly from label __gray_sync_n_count.
+| So don't move it do somewhere else!)
+|------------------------------------------------------------------------------
+__gray_plane_index:
+	.word    0x0000
+|==============================================================================
+| Interrupt 1 handler for HW2
+|
+| port 70001D (bit 7) is used to synchronized to the LCD hardware. Here are the
+| docs of this port (taken from Johan Eilert's j89hw.txt)
+|
+| $70001D RW ($06)
+|	:7	 Toggles every FS (every time the LCD restarts at line 0)
+|	:6-4	-
+|	:3	 Battery checker bit B (? ???)
+|	:2	 ? (set)
+|	:1	 Screen enable (clear this bit to shut down LCD)
+|	:0	 Battery checker bit A (? enable $600000:2)
+|	     (AMS:) The battery checker bits must both be set (AB=11) prior to
+|	     checking the voltage level with $600000:2.  Then, after use, bit B
+|	     must be cleared (AB=10) while the battery trig hardware settles to
+|	     the "rest" voltage value (%111).  Finally, both bits should be
+|	     cleared.
+|==============================================================================
+__gray_int1_handler_hw2:
+	move.w   %sr,-(%a7)                | save content of status register on stack
+	move.w   #0x2700,%sr               | disable ALL interrupts (no one should
+	                                   | interrupt us ...)
+	movem.l  %d0-%d7/%a0-%a6,-(%a7)
+__gray_startagain:
+	moveq    #0x0,%d1
+	lea      (__gray_sync_n_count,%pc),%a0
+	move.w   (%a0),%d0
+	bne.s    __gray_copy_first_or_sec  | there is a third of the plane left to
+	                                   | copy -> do it now!
+	move.l   (%a0),%d0
+.ifdef ALWAYS_HW2_TESTING
+	move.b   %d0,%d1
+	eor.b    #0x80,%d1
+.else
+	move.b   0x70001D,%d1              | get flipping bit
+	eor.b    %d0,%d1
+	bpl      __gray_to_oldint          | not flipped yet -> proceed to previous
+	                                   | installed int handler
+.endif
+	eor.l    %d1,(%a0)                 | store new flip "bit" and reset the
+	                                   | work left status
+
+    |--------------------------------------------------------------------------
+    | NOTE: if we detect a pageflip we start our copying work with the lowest
+    |       third. this way it will not interfere with the LCD hardware refresh
+    |
+    | The 3 thirds are copied in the following order:
+    |
+    | last third -> first third -> second third
+    |--------------------------------------------------------------------------
+	move.w   #0xA00,%d0
+__gray_copy_next_third:
+	addq.w   #1,(%a0)+
+	bra.s    __gray_perform_copying
+__gray_copy_first_or_sec:
+    |--------------------------------------------------------------------------
+    | if __gray_sync_n_count == 1 -> copy first third of screen
+    | otherwise -> set __gray_sync_n_count to 0 and copy second third of screen
+    |--------------------------------------------------------------------------
+	subq.w   #1,%d0
+	beq.s    __gray_copy_next_third
+	clr.w    (%a0)+
+	move.w   #0x500,%d0             | setup to copy second third of screen
+__gray_perform_copying:
+	move.b   (%a0),%d1              | fetch index of plane to draw next
+	beq      __gray_update_index    | skip index 0 -> stay at darkplane
+
+    |--------------------------------------------------------------------------
+    | If we'll come here we will copy 1 third of the screen from a specific
+    | plane to the video buffer at 0x4c00. Register D0 holds the offset of
+    | which third should be copied and register D1 contains the "index" of the
+    | "source" plane
+    |
+    | index = 0 -> darkplane (skipped, will not come here!)
+    | index = 4 -> darkplane
+    | index = 8 -> lightplane
+    |
+    | Due to the fact that the indices are cycled from 8 down to 0 the skipped
+    | index 0 causes the darkplane to stay active twice as long as the light
+    | plane.
+    |
+    | The copying is performed in a kind of "hardcore" style by using 13
+    | registers. This way 52 Bytes are copied with a single instruction.
+    |--------------------------------------------------------------------------
+
+    |--------------------------------------------------------------------------
+    | doublebuffer extension ... add content of __gray_dbl_offset to %d0
+    |--------------------------------------------------------------------------
+	add.w    (__gray_dbl_offset,%pc),%d1
+	neg.w    %d1
+	movea.l  (__gray_used_mem,%pc,%d1.w),%a0
+
+	lea      0x4C00,%a1
+	adda.w   %d0,%a0
+	adda.w   %d0,%a1
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x34,%a1)  | size of this instruction: 6 bytes
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6      | size of this instruction: 4 bytes
+	movem.l  %d0-%d7/%a2-%a6,(0x68,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x9C,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0xD0,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x104,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x138,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x16C,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x1A0,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x1D4,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x208,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x23C,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x270,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x2A4,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x2D8,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x30C,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x340,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x374,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x3A8,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x3DC,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x410,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x444,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x478,%a1)
+	movem.l  (%a0)+,%d0-%d7/%a2-%a6
+	movem.l  %d0-%d7/%a2-%a6,(0x4AC,%a1)
+	movem.l  (%a0)+,%d0-%d7
+	movem.l  %d0-%d7,(0x4E0,%a1)
+
+    |--------------------------------------------------------------------------
+    | evaluate if there is still a third of the screen to copy or if we
+    | should proceed to the next plane
+    |--------------------------------------------------------------------------
+__gray_update_index:
+	lea      (__gray_sync_n_count,%pc),%a0
+	move.w   (%a0)+,%d0
+	beq      __gray_startagain          | no third left to copy -> check again
+	                                    | the pageflip bit if yet a pageflip
+	                                    | had occured
+	subq.w   #1,%d0
+	bne.s    __gray_to_oldint           | if there is "copy work" left ->
+	                                    | don't modify the plane to display
+
+	lea      (__switch_cnt,%pc),%a1     | increment switch count here, because
+	addq.l   #1,(%a1)                   | a complete page was drawn if we come here
+
+	subq.b   #4,(%a0)                   | cycle __gray_plane_index by decrementing
+	bcc.s    __gray_to_oldint           | it and wrap around to 8 if negative.
+	move.b   #0x8,(%a0)
+__gray_to_oldint:
+	movem.l  (%a7)+,%d0-%d7/%a0-%a6
+	move.w   (%a7)+,%sr                 | restore content of status register
+    |--------------------------------------------------------------------------
+    |  JUMP to previous installed interrupt handler
+    |--------------------------------------------------------------------------
+	.word    0x4ef9                     | opcode of "JMP address" instruction
+__gray_old_int1_hw2:
+	.long    0x00000000
+|==============================================================================
+| INTERNAL: initialize grayscale handler
+|==============================================================================
+__gray_init_handler:
+	lea      (__L_plane,%pc),%a0
+	move.w   #0x3BF,%d1
+	move.w   (__gray_hw_type,%pc),%d0
+	tst.w    %d0
+	beq.s    __gray_init_hw1_handler
+
+    |--------------------------------------------------------------------------
+    | HW2 specific initializations:
+    |
+    | (1) set __D_plane to __gray_used_mem
+    | (2) copy content of 0x4c00 to darkplane
+    | (3) "backup" old INT1 handler in __gray_old_int1_hw2 (the address part
+    |     of a JUMP address instruction at the end of the HW2 int handler)
+    | (4) install our own INT1 HW2 handler
+    |--------------------------------------------------------------------------
+	movea.l  (__gray_used_mem,%pc),%a1
+	move.l   %a1,(0x4,%a0)               | set __D_plane
+	movea.w  #0x4C00,%a0
+	move.w   %d1,%d0
+__gray_cpy_d_plane:
+	move.l   (%a0)+,(%a1)+
+	dbf      %d0, __gray_cpy_d_plane
+	lea      (__gray_int1_handler_hw2,%pc),%a0
+
+    | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+    | the following command should be unnecessary; I commented it out (TOM)
+    | (__L_plane should be already set by __gray_init_mem)
+    | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+	|move.l   %a1,(__L_plane - __gray_int1_handler_hw2,%a0)
+
+	move.l   0x64,(__gray_old_int1_hw2 - __gray_int1_handler_hw2,%a0)
+	bra.s    __gray_init_proceed
+    |--------------------------------------------------------------------------
+    | HW1 specific initializations:
+    |
+    | (1) "backup" old INT1 handler in __gray_old_int1_hw1 (the address part
+    |     of a JUMP address instruction at the end of the HW1 int handler)
+    | (2) install our own INT1 HW1 handler
+    |--------------------------------------------------------------------------
+__gray_init_hw1_handler:
+	move.l   (%a0),%a1
+	lea      (__gray_int1_handler_hw1,%pc),%a0
+	move.l   0x64,(__gray_old_int1_hw1 - __gray_int1_handler_hw1,%a0)
+__gray_init_proceed:
+	bclr.b   #2,0x600001
+	move.l   %a0,0x64:w
+	bset.b   #2,0x600001
+__gray_clr_l_plane:
+    |--------------------------------------------------------------------------
+    | clear light plane (done for both HW types)
+    |--------------------------------------------------------------------------
+	clr.l    (%a1)+
+	dbf      %d1, __gray_clr_l_plane
+    |--------------------------------------------------------------------------
+    | PortSet(__D_plane,239,127)
+    |--------------------------------------------------------------------------
+	move.l   #0xEF007F,-(%a7)
+	move.l   (__D_plane,%pc),-(%a7)
+	movea.l  0xC8,%a0
+	lea      (0x1A2*4,%a0),%a0 /* PortSet */
+	movea.l  (%a0),%a1
+	jsr      (%a1)
+	addq.w   #8,%a7
+__gray_ok:
+	lea (__L_plane,%pc),%a0
+	lea (__L_plane2,%pc),%a1
+	move.l (%a0)+,(%a1)+        | copy __L_plane to __L_plane2
+	move.l (%a0)+,(%a1)+        | copy __D_plane to __D_plane2
+	moveq    #0x1,%d0
+	rts
+|==============================================================================
+|  EXPORTED: GrayOff function (turn grayscales off)
+|            NOTE: ALWAYS returns 1 !!
+|==============================================================================
+GrayOff:
+	movem.l  %a2-%a3,-(%a7)
+	lea      (__gray_handle,%pc),%a3
+	tst.w    (%a3)
+	beq      __gray_off_out                   | no handle? -> nothing to do
+	move.w   (__gray_hw_type,%pc),%d0
+	tst.w    %d0
+	beq.s    __gray_hw1_cleanup
+    |--------------------------------------------------------------------------
+    | cleanup for HW2 calcs
+    |--------------------------------------------------------------------------
+	bclr.b   #2,0x600001
+	move.l   (__gray_old_int1_hw2,%pc),0x64:w   | restore old INT1 handler
+	bset.b   #2,0x600001
+	movea.l  (__D_plane,%pc),%a1
+	movea.w  #0x4C00,%a0
+	move.w   #0x3BF,%d0                   | copy content of darkplane to 0x4c00
+__gray_dark2lcd:
+	move.l   (%a1)+,(%a0)+
+	dbf      %d0, __gray_dark2lcd
+	bra.s    __gray_continue_cleanup
+    |--------------------------------------------------------------------------
+    | cleanup for HW1 calcs (on HW1 0x4c00 is used as darkplane. We haven't to
+    | set it)
+    |--------------------------------------------------------------------------
+__gray_hw1_cleanup:
+	move.w   #0x980,0x600010                    | restore used plane to 0x4c00
+	move.l   (__gray_old_int1_hw1,%pc),0x40064  | restore old INT1 handler
+	| (We can use 0x40064 here because it is HW1 only.)
+
+__gray_continue_cleanup:
+	lea      (__L_plane,%pc),%a0  | restore plane pointers to 0x4c00 for sure
+	move.l   #0x04c00,(%a0)+
+	move.l   #0x04c00,(%a0)+
+	move.l   #0x04c00,(%a0)
+    |--------------------------------------------------------------------------
+    | HeapFree(__gray_handle)
+    |--------------------------------------------------------------------------
+	movea.l  0xc8,%a0
+	lea      (0x97*4,%a0),%a0 /* HeapFree */
+	move.w   (%a3),-(%a7)
+	move.l   (%a0),%a2
+	jsr      (%a2)
+	addq.l   #2,%a7
+    |--------------------------------------------------------------------------
+    | PortRestore()
+    |--------------------------------------------------------------------------
+	movea.l  0xc8,%a0
+	lea      (0x1A3*4,%a0),%a0 /* PortRestore */
+	move.l   (%a0),%a2
+	jsr      (%a2)
+	clr.l    (%a3)                     | 0->handle AND(!!) 0->__gray_dbl_offset
+	lea      (__gray_sync_n_count,%pc),%a0
+	clr.l    (%a0)
+__gray_off_out:
+	movem.l  (%a7)+,%a2-%a3
+	jbra     __gray_ok
+
+| #############################################################################
+|  Revision History
+| #############################################################################
+|
+| $Log: not supported by cvs2svn $
+| Revision 3.11 2004/02/25 03:49:03  Kevin Kofler
+| Don't use 0x40000 to set interrupts on code path that affect HW3.
+| Use 0xE00000 as ROM_base mask instead of 0x600000.
+| Bumped version to 3.51.
+|
+| Revision 3.10 2002/04/05 11:34:23  tnussb
+| (1) Resets now __D_plane2,__L_plane2 and __gray_dbl_offset at end of GrayOn()
+|     to make sure nothing happens if doublebuffer macros get called without
+|     setting a buffer first. Nevertheless NO program should call one of the
+|     doublebuffer macros without setting a buffer previously.
+| (2) Some further size optimizations. Now the size is exactly as long as
+|     without before the integration of doublebuffering. Quite smart, isn't it?
+|     More functionality, some minor drawbacks fixed and no increase in size ...
+| (3) Changed return value of GrayOff() function to void.
+|
+| Revision 3.9  2002/04/04 18:50:36  tnussb
+| first working version of internal doublebuffer support (not checked on
+| real calcs yet, but on the VTI)
+|
+| Revision 3.8  2002/04/04 16:39:05  tnussb
+| Debug version checked in previously. This one is the correct one.
+|
+| Revision 3.7  2002/04/04 16:35:20  tnussb
+| (1) documentation of HW2 interrupt handler heavily extended
+| (2) HW2: plane switch counting fixed (was incremented too often previously)
+| (3) global ALWAYS_HW2_TESTING added which can be used to force the use of
+|     HW2 grayscales. Now the HW2 grayscales can be tested on the VTI if
+|     this global is defined. Of course this will flicker extremely, because
+|     the VTI doesn't simulate port 70001D, but its still better than no
+|     testing possibility.
+| (4) don't trashes %sr on HW2 anymore (restores previous setting)
+| (5) This version was tested on a real HW1 and a real HW2 calc. It works.
+|     (Thanx to Sebastian Reichelt and stoopid guy)
+|
+| Revision 3.6  2002/04/04 11:58:19  tnussb
+| (1) size optimizations
+| (2) unnecessary cleanup removed from GrayOff()
+| (3) interrupt handler for HW1 rewritten (uses now plane pointer directly)
+| (4) "heavily" documented
+|
+| Revision 3.5  2002/04/04 11:54:39  tnussb
+| (1) exports __gray_old_int1_hw1 and __gray_old_int1_hw2. this way it is
+|     possible to modify them after grayscales are turned on
+| (2) comments changed to GNU Assembler style
+| [NOTE: CVS time and date doesn't fit to real implementation data]
+|
+| Revision 3.0  2002/04/04 11:50:56  tnussb
+| grayscale support used for TIGCC up to version v0.93
+| [NOTE: CVS time and date doesn't fit to real implementation data]
+|

+ 10 - 0
tigcc/archive/gray_throw.s

@@ -0,0 +1,10 @@
+	.xdef GrayOnThrow
+
+.text
+GrayOnThrow:
+	jbsr GrayOn
+	tst.w %d0
+	jbne .L__finished
+	.word 0xA000+850
+.L__finished:
+	rts

+ 1 - 0
tigcc/archive/grayversion.c

@@ -0,0 +1 @@
+volatile char __gray_version[] = "[TIGCCLIB GraySupport v3.51 "__DATE__" "__TIME__"]";

+ 8 - 0
tigcc/archive/grayversion.s

@@ -0,0 +1,8 @@
+	.file	"grayversion.c"
+#NO_APP
+	.text
+tigcc_compiled.:
+	.globl	__gray_version
+	.text
+__gray_version:
+	.ascii "[TIGCCLIB GraySupport v3.51 Sep  6 2004 00:18:08]\0"

+ 22 - 0
tigcc/archive/homestore.s

@@ -0,0 +1,22 @@
+| Workaround for HomePushEStack which does not redraw the Home screen
+| Copyright (C) Samuel Stearley, 2002
+
+	.xdef HomeStore
+
+.text
+HomeStore:
+	move.l %a3,-(%sp)
+	move.l 0xC8,%a1
+	move.l 0x2A3*4(%a1),%a3 /* EV_hook */
+	move.l (%a3),-(%sp)
+	lea .L__NewHook,%a0
+	move.l %a0,(%a3)
+	move.l 0x10F*4(%a1),%a0 /* HomePushEStack */
+	jsr (%a0)
+	move.l (%sp)+,(%a3)
+	move.l (%sp)+,%a3
+	rts
+.L__NewHook:
+	move.l 4(%sp),%a0
+	move.w #0x700,(%a0)
+	rts

+ 25 - 0
tigcc/archive/homestorepair.c

@@ -0,0 +1,25 @@
+#include <homescr.h>
+#include <error.h>
+#include <alloc.h>
+
+__ATTR_LIB_C__ void HomeStorePair(HANDLE Entry, HANDLE Ans)
+{
+  HANDLE hNode;
+  TRY
+    hNode = HS_newFIFONode ();
+  ONERR
+    HeapFree (Entry);
+    if (Ans != Entry)
+      HeapFree (Ans);
+    PASS;
+  ENDTRY
+  TRY
+    FIFO_NODE *Node = HeapDeref (hNode);
+    Node->Entry.Expr = Entry;
+    Node->Ans.Expr = Ans;
+    HS_pushEmptyFIFONode (hNode);
+  ONERR
+    HS_freeFIFONode (hNode);
+    PASS;
+  ENDTRY
+}

+ 83 - 0
tigcc/archive/homestorepair.s

@@ -0,0 +1,83 @@
+	.file	"homestorepair.c"
+#NO_APP
+	.text
+tigcc_compiled.:
+#APP
+	.set _A_LINE,0xA000
+#NO_APP
+	.text
+	.even
+	.globl	HomeStorePair
+HomeStorePair:
+	link.w %a6,#-120
+	movm.l #0x1e00,-(%sp)
+	move.w %d0,%d5
+	move.w %d1,%d6
+	move.l 200.w,%a0
+	pea -60(%a6)
+	move.l 1360(%a0),%a0
+	jbsr (%a0)
+	move.w %d0,%d3
+	addq.l #4,%sp
+	move.l 200.w,%a0
+	jbeq .L7
+	move.w %d5,-(%sp)
+	move.l 604(%a0),%a0
+	jbsr (%a0)
+	addq.l #2,%sp
+	cmp.w %d6,%d5
+	jbeq .L4
+	move.l 200.w,%a0
+	move.w %d6,-(%sp)
+	move.l 604(%a0),%a0
+	jbsr (%a0)
+	addq.l #2,%sp
+.L4:
+	move.l 200.w,%a0
+	move.l 1356(%a0),%a0
+	move.w %d3,-(%sp)
+	jbra .L8
+	.even
+.L7:
+	move.l 2324(%a0),%a0
+	jbsr (%a0)
+	move.w %d0,%d3
+	move.l 200.w,%a0
+	move.l 1364(%a0),%a0
+	jbsr (%a0)
+	move.l 200.w,%a0
+	pea -120(%a6)
+	move.l 1360(%a0),%a0
+	jbsr (%a0)
+	move.w %d0,%d4
+	addq.l #4,%sp
+	move.l 200.w,%a0
+	jbne .L5
+	move.w %d3,-(%sp)
+	move.l 600(%a0),%a0
+	jbsr (%a0)
+	move.w %d5,16(%a0)
+	move.w %d6,42(%a0)
+	jbsr __get_HS_pushEmptyFIFONode
+	move.w %d3,-(%sp)
+	jbsr (%a0)
+	move.l 200.w,%a0
+	move.l 1364(%a0),%a0
+	jbsr (%a0)
+	addq.l #4,%sp
+	jbra .L1
+	.even
+.L5:
+	move.w %d3,-(%sp)
+	move.l 2304(%a0),%a0
+	jbsr (%a0)
+	move.l 200.w,%a0
+	move.l 1356(%a0),%a0
+	move.w %d4,-(%sp)
+.L8:
+	jbsr (%a0)
+	.even
+.L1:
+	movm.l -136(%a6),#0x78
+	unlk %a6
+	rts

+ 15 - 0
tigcc/archive/hrealloc_throw.s

@@ -0,0 +1,15 @@
+	.xdef HeapReallocThrow
+
+.text
+HeapReallocThrow:
+	pea.l (%a0)
+	move.w %d0,-(%sp)
+	move.l 0xC8,%a0
+	move.l (%a0,0x9D*4),%a0 /* HeapRealloc */
+	jsr (%a0)
+	addq.l #6,%sp
+	tst.w %d0
+	jbne .L__finished
+	.word 0xA000+670
+.L__finished:
+	rts

+ 49 - 0
tigcc/archive/hw_version.s

@@ -0,0 +1,49 @@
+| Hardware version detection, adapted from gray.s
+| Copyright (C) 2002 Thomas Nussbaumer.
+| Copyright (C) 2003 Kevin Kofler.
+| See License.txt for licensing conditions.
+
+	.xdef __get_hw_version
+
+__get_hw_version:
+    |--------------------------------------------------------------------------
+    | get the HW parm block using the algorithm suggested by Julien Muchembled
+    |--------------------------------------------------------------------------
+	move.l   0xc8:w,%d0
+	andi.l   #0xE00000,%d0 | get the ROM base
+	movea.l  %d0,%a0
+	movea.l  260(%a0),%a1  | get pointer to the hardware param block
+	adda.l   #0x10000,%a0
+	cmpa.l   %a0,%a1       | check if the HW parameter block is near enough
+	bcc.s    L.is_hw1      | if it is too far, it is HW1
+	cmpi.w   #22,(%a1)     | check if the parameter block contains HW ver
+	bls.s    L.is_hw1      | if it is too small, it is HW1
+
+    |--------------------------------------------------------------------------
+    | check for VTI (trick suggested by Julien Muchembled)
+    |--------------------------------------------------------------------------
+	trap     #12         | enter supervisor mode. returns old (%sr) in %d0.w
+	move.w   #0x3000,%sr | set a non-existing flag in %sr (but keep s-flag)
+	move.w   %sr,%d1     | get %sr content and check for non-existing flag
+	move.w   %d0,%sr     | restore old %sr content
+	btst.l   #12,%d1     | this non-existing flag can only be set on the VTI
+	beq.s    L.not_vti   | flag not set -> no VTI
+
+    |--------------------------------------------------------------------------
+    | VTI detected -> treat as HW1
+    |--------------------------------------------------------------------------
+	| Fall through...
+
+L.is_hw1:
+    |--------------------------------------------------------------------------
+    | HW1 detected
+    |--------------------------------------------------------------------------
+	moveq.l  #1,%d0      | set %d0 to 1 (HW1)
+	rts                  | return 1
+
+L.not_vti:
+    |--------------------------------------------------------------------------
+    | Real calculator detected, so read the HW version from the HW parm block
+    |--------------------------------------------------------------------------
+	move.l   22(%a1),%d0 | get the hardware version
+	rts                  | return it

+ 5 - 0
tigcc/archive/isextalnum.s

@@ -0,0 +1,5 @@
+	.xdef _extalnum_list
+
+.data
+_extalnum_list:
+	.long 0, 65283, -16777337, -16777465, -1106176, 8192, -32769, -32769

+ 5 - 0
tigcc/archive/isextpunct.s

@@ -0,0 +1,5 @@
+	.xdef _extpunct_list
+
+.data
+_extpunct_list:
+	.long 12648447, -16842500, 16777336, 16777464, 1106175, -8193, 32768, 32768

+ 7 - 0
tigcc/archive/kbd_queue.s

@@ -0,0 +1,7 @@
+	.xdef kbd_queue
+
+.text
+kbd_queue:
+	moveq.l #6,%d0
+	trap #9
+	rts

+ 15 - 0
tigcc/archive/loaddll_throw.s

@@ -0,0 +1,15 @@
+| Warning: This routine has the attribute __ATTR_LIB_C__!
+| It is a simple wrapper for a C function.
+
+	.xdef LoadDLLThrow
+
+.text
+LoadDLLThrow:
+	lea.l .L__finished+2,%a0
+	move.l (%sp)+,(%a0)
+	jbsr LoadDLL
+	tst.w %d0
+	jbeq .L__finished
+	.word 0xA000+850
+.L__finished:
+	jmp.l 0:l

+ 24 - 0
tigcc/archive/lshrdi.s

@@ -0,0 +1,24 @@
+|lshrdi3 routine copyright (C) 2002, Kevin Kofler
+
+	.xdef __lshrdi3
+
+.text
+__lshrdi3:
+	tst.w 12(%a7)
+	bne.s .L__lshrdi3_return0
+	move.l 4(%a7),%d0
+	move.l 8(%a7),%d1
+	move.w 14(%a7),%d2
+	beq.s .L__lshrdi3_returnn
+	subq.w #1,%d2
+.L__lshrdi3_loop:
+	lsr.l #1,%d0
+	roxr.l #1,%d1
+	dbra.w %d2,.L__lshrdi3_loop
+.L__lshrdi3_returnn:
+	rts
+
+.L__lshrdi3_return0:
+	moveq.l #0,%d0
+	moveq.l #0,%d1
+	rts

+ 15 - 0
tigcc/archive/malloc_throw.s

@@ -0,0 +1,15 @@
+	.xdef malloc_throw,HeapAllocPtrThrow
+
+.text
+malloc_throw:
+HeapAllocPtrThrow:
+	pea.l (%a0)
+	move.l 0xC8,%a0
+	move.l (%a0,0xA2*4),%a0 /* HeapAllocPtr */
+	jsr (%a0)
+	addq.l #4,%sp
+	move.l %a0,%d0
+	jbne .L__finished
+	.word 0xA000+670
+.L__finished:
+	rts

+ 30 - 0
tigcc/archive/moddi.s

@@ -0,0 +1,30 @@
+|moddi3 routine copyright (C) 2002, Kevin Kofler
+|WARNING: Division by 0 will be handled the same way as in the unsigned variant.
+|         For my __umoddi3, this means:
+|         A division by 0 will not cause an exception, but just crash in an
+|         infinite loop!
+
+	.xdef __moddi3
+
+.text
+__moddi3:
+	tst.b 12(%a7)	
+	bge.s .L__moddi3_denom_positive
+	neg.l 16(%a7)
+	negx.l 12(%a7)
+.L__moddi3_denom_positive:
+	tst.b 4(%a7)
+	blt.s .L__moddi3_numer_negative
+.L__moddi3_umoddi3:
+	jbra __umoddi3
+
+.L__moddi3_numer_negative:
+	neg.l 8(%a7)
+	negx.l 4(%a7)
+	lea.l (.L__moddi3_return_jump+2,%PC),%a0
+	move.l (%a7)+,(%a0)
+	bsr.s .L__moddi3_umoddi3
+	neg.l %d1
+	negx.l %d0
+.L__moddi3_return_jump:
+	jmp.l 0:l

+ 6 - 0
tigcc/archive/modsi.s

@@ -0,0 +1,6 @@
+	.xdef __modsi3
+
+.text
+__modsi3:
+	move.w #0x2A9*4,%d2 /* _ms32s32 */
+	jra __div_entry

+ 6 - 0
tigcc/archive/mulbf.s

@@ -0,0 +1,6 @@
+	.xdef __mulbf3
+
+.text
+__mulbf3:
+	moveq.l #8,%d0
+	jra __fp_entry

+ 58 - 0
tigcc/archive/muldi.s

@@ -0,0 +1,58 @@
+|muldi3 routine copyright (C) 2002, Kevin Kofler
+
+	.xdef __muldi3
+
+.text
+__muldi3:
+	move.w 18(%a7),%d0
+	mulu 4(%a7),%d0
+	move.w 16(%a7),%d2
+	mulu 6(%a7),%d2
+	add.w %d2,%d0
+	move.w 14(%a7),%d2
+	mulu 8(%a7),%d2
+	add.w %d2,%d0
+	move.w 12(%a7),%d2
+	mulu 10(%a7),%d2
+	add.w %d2,%d0
+	swap %d0
+	clr.w %d0
+
+	move.w 18(%a7),%d2
+	mulu 6(%a7),%d2
+	add.l %d2,%d0
+	move.w 16(%a7),%d2
+	mulu 8(%a7),%d2
+	add.l %d2,%d0
+	move.w 14(%a7),%d2
+	mulu 10(%a7),%d2
+	add.l %d2,%d0
+
+	move.w 18(%a7),%d1
+	mulu 8(%a7),%d1
+	swap %d1
+	add.w %d1,%d0
+	clr.w %d1
+	swap %d0
+	addx.w %d1,%d0
+	swap %d0
+
+	move.w 16(%a7),%d2
+	mulu 10(%a7),%d2
+	swap %d2
+	add.w %d2,%d0
+	clr.w %d2
+	swap %d0
+	addx.w %d2,%d0
+	swap %d0
+	add.l %d2,%d1
+	moveq.l #0,%d2
+	addx.l %d2,%d0
+
+	move.w 18(%a7),%d2
+	mulu 10(%a7),%d2
+	add.l %d2,%d1
+	moveq.l #0,%d2
+	addx.l %d2,%d0
+
+	rts

+ 17 - 0
tigcc/archive/mulsi.s

@@ -0,0 +1,17 @@
+	.xdef __mulsi3
+
+.text
+__mulsi3:
+	move.l (4,%sp),%d1
+	move.l (8,%sp),%d2
+	move.l %d2,%d0
+	mulu %d1,%d0
+	swap %d2
+	mulu %d1,%d2
+	swap %d1
+	mulu (10,%sp),%d1
+	add.w %d1,%d2
+	swap %d2
+	clr.w %d2
+	add.l %d2,%d0
+	rts

+ 6 - 0
tigcc/archive/negbf.s

@@ -0,0 +1,6 @@
+	.xdef __negbf2
+
+.text
+__negbf2:
+	moveq.l #16,%d0
+	jra __fp_entry

+ 8 - 0
tigcc/archive/nocallback.s

@@ -0,0 +1,8 @@
+| Warning: This routine has the attribute __ATTR_TIOS_CALLBACK__!
+
+	.xdef NoCallBack
+
+.text
+NoCallBack:
+	moveq.l #1,%d0
+	rts

+ 22 - 0
tigcc/archive/prgstart.s

@@ -0,0 +1,22 @@
+	.xdef PRG_getStart
+
+.text
+PRG_getStart:
+	move.w #0x700,%d0
+	trap #1
+	lea.l 0x600017,%a0
+	move.b -2(%a0),%d1
+	bset #3,-2(%a0)
+.L__PRG_getStart_ne_loop:
+	tst.b (%a0)
+	bne.s .L__PRG_getStart_ne_loop
+.L__PRG_getStart_eq_loop:
+	move.b (%a0),%d2
+	beq.s .L__PRG_getStart_eq_loop
+	btst #3,%d1
+	bne.s .L__PRG_getStart_done
+	bclr #3,-2(%a0)
+.L__PRG_getStart_done:
+	trap #1
+	move.b %d2,%d0
+	rts

+ 17 - 0
tigcc/archive/printf.s

@@ -0,0 +1,17 @@
+| Warning: This routine has the attribute __ATTR_TIOS__!
+
+	.xdef printf
+
+.text
+printf:
+	movea.l 0xC8,%a0
+	movea.l (%a0,0x14C),%a0 /* vcbprintf */
+	lea (%a0,32),%a0
+	movea.w (%a0),%a1
+	pea (%sp,8)
+	move.l (%sp,8),-(%sp)
+	clr.l -(%sp)
+	pea fputchar
+	jsr (%a0.l,%a1)
+	lea (%sp,16),%sp
+	rts

+ 43 - 0
tigcc/archive/push_longint.s

@@ -0,0 +1,43 @@
+	.xdef push_longint
+
+.text
+push_longint:
+| Saving %d2 as well is a really dirty trick to reserve four extra bytes on the stack.
+| Only two are needed, but this is smaller than subtracting and adding.
+	movem.l %d2-%d6/%a5,-(%sp)
+| Put address of push_quantum into %a5.
+	move.l 0xC8,%a5
+	move.l (%a5,3000),%a5  /* push_quantum */
+| %d4: Number of bytes.
+	clr.w %d4
+| Put POSINT_TAG in %d6.
+	moveq.l #31,%d6
+| Move parameter to %d3.
+	move.l 28(%sp),%d3
+| If it is zero, the value should be zero bytes long.
+	jbeq .L__finished
+| If negative, put NEGINT_TAG in %d6 and negate it.
+	jbge .L__mainloop
+	moveq.l #32,%d6
+	neg.l %d3
+.L__mainloop:
+| Push rightmost quantum of the value.
+	move.w %d3,(%sp)
+	jsr (%a5)
+| Add 1 to the number of bytes.
+	addq.w #1,%d4
+| Shift the value to the right by one quantum.
+	lsr.l #8,%d3
+| Finished if remaining value is zero.
+	jbne .L__mainloop
+.L__finished:
+| Push number of bytes.
+	move.w %d4,(%sp)
+	jsr (%a5)
+| Push tag.
+	move.w %d6,(%sp)
+	jsr (%a5)
+| See above.
+| There is no problem in "restoring" %d2, since it may be trashed.
+	movem.l (%sp)+,%d2-%d6/%a5
+	rts

+ 50 - 0
tigcc/archive/push_longlongint.s

@@ -0,0 +1,50 @@
+	.xdef push_longlongint
+
+.text
+push_longlongint:
+| Saving %d2 as well is a really dirty trick to reserve four extra bytes on the stack.
+| Only two are needed, but this is smaller than subtracting and adding.
+	movem.l %d2-%d7/%a5,-(%sp)
+| Put address of push_quantum into %a5.
+	move.l 0xC8,%a5
+	move.l (%a5,3000),%a5  /* push_quantum */
+| %d7: Number of bytes.
+	clr.w %d7
+| Put POSINT_TAG in %d6.
+	moveq.l #31,%d6
+| Move parameter to %d3/%d4.
+	movem.l 32(%sp),%d3-%d4
+| If negative, put NEGINT_TAG in %d6 and negate it.
+| We only need to look at %d3 because of how numbers are stored.
+	tst.l %d3
+	jbge .L__mainloop
+	moveq.l #32,%d6
+	neg.l %d4
+	negx.l %d3
+.L__mainloop:
+| Finished if remaining value is zero.
+	move.l %d3,%d0
+	or.l %d4,%d0
+	jbeq .L__finished
+| Push rightmost quantum of the value.
+	move.w %d4,(%sp)
+	jsr (%a5)
+| Add 1 to the number of bytes.
+	addq.w #1,%d7
+| Shift the value to the right by one quantum.
+	move.b %d3,%d4
+	lsr.l #8,%d3
+	ror.l #8,%d4
+| Always repeat the loop at this point.
+	jbra .L__mainloop
+.L__finished:
+| Push number of bytes.
+	move.w %d7,(%sp)
+	jsr (%a5)
+| Push tag.
+	move.w %d6,(%sp)
+	jsr (%a5)
+| See above.
+| There is no problem in "restoring" %d2, since it may be trashed.
+	movem.l (%sp)+,%d2-%d7/%a5
+	rts

+ 43 - 0
tigcc/archive/push_shortint.s

@@ -0,0 +1,43 @@
+	.xdef push_shortint
+
+.text
+push_shortint:
+| Saving %d2 as well is a really dirty trick to reserve four extra bytes on the stack.
+| Only two are needed, but this is smaller than subtracting and adding.
+	movem.l %d2-%d6/%a5,-(%sp)
+| Put address of push_quantum into %a5.
+	move.l 0xC8,%a5
+	move.l (%a5,3000),%a5  /* push_quantum */
+| %d4: Number of bytes.
+	clr.w %d4
+| Put POSINT_TAG in %d6.
+	moveq.l #31,%d6
+| Move parameter to %d3.
+	move.w 28(%sp),%d3
+| If it is zero, the value should be zero bytes long.
+	jbeq .L__finished
+| If negative, put NEGINT_TAG in %d6 and negate it.
+	jbge .L__mainloop
+	moveq.l #32,%d6
+	neg.w %d3
+.L__mainloop:
+| Push rightmost quantum of the value.
+	move.w %d3,(%sp)
+	jsr (%a5)
+| Add 1 to the number of bytes.
+	addq.w #1,%d4
+| Shift the value to the right by one quantum.
+	lsr.w #8,%d3
+| Finished if remaining value is zero.
+	jbne .L__mainloop
+.L__finished:
+| Push number of bytes.
+	move.w %d4,(%sp)
+	jsr (%a5)
+| Push tag.
+	move.w %d6,(%sp)
+	jsr (%a5)
+| See above.
+| There is no problem in "restoring" %d2, since it may be trashed.
+	movem.l (%sp)+,%d2-%d6/%a5
+	rts

+ 16 - 0
tigcc/archive/pushfifonode.c

@@ -0,0 +1,16 @@
+#include <homescr.h>
+#include <error.h>
+
+__ATTR_LIB_C__ __HS_pushEmptyFIFONode__type__ __get_HS_pushEmptyFIFONode(void)
+{
+  short *Ptr = (void*)HomePushEStack, *EndPtr = Ptr + 0x80;
+  for (; (unsigned long)Ptr < (unsigned long)EndPtr; Ptr++)
+    if (*Ptr == 0x4EBA) /* bsr */
+      {
+        Ptr++;
+        void *Addr = (char*)Ptr + *Ptr;
+        if (Addr != HS_newFIFONode)
+          return Addr;
+      }
+  ER_throw (410);
+}

Some files were not shown because too many files changed in this diff