ref: 4c670f454f76120455674cd064d3f9bbb2e0d2aa
parent: 0441e14568c0254ba99e516d1282fd196cb1e0a3
author: Konstantinn Bonnet <[email protected]>
date: Wed Mar 23 19:18:29 EDT 2016
implement drawing text, highscores
--- a/dat.h
+++ b/dat.h
@@ -56,12 +56,12 @@
extern uchar *pict;
struct Fnt{
- s16int h;
- s16int ofs[256];
+ int h;
+ int ofs[256];
char w[256];
Dat;
};
-extern Fnt fnts[];
+extern Fnt fnts[], *fnt;
struct Sfx{
Dat pc;
--- a/fns.h
+++ b/fns.h
@@ -2,13 +2,16 @@
void* erealloc(void *, ulong);
void flush(void);
void dat(char *);
+void palpic(uchar *);
+void fadeout(int);
+void fadein(int);
void out(void);
void put(int, int, int, int, uchar *, int);
+int txt(int, int, char *, int);
+int txtnl(int, int, char *, int);
+int txtw(char *s);
void fill(int);
-void palpic(uchar *);
void pic(int, int, int);
-void fadein(int);
-void fadeout(int);
void demos(void);
void init(void);
int rnd(void);
--- a/fs.c
+++ b/fs.c
@@ -841,7 +841,7 @@
static void
getfnts(Biobuf *dat, Biobuf *aux, u16int hf[])
{
- s16int *o;
+ int *o;
u32int v, n;
uchar *u, *p;
char *w;
@@ -855,7 +855,7 @@
unhuff(dat, hf, u, n);
f->h = GBIT16(p), p+=2;
for(o=f->ofs; o < f->ofs+nelem(f->ofs); o++)
- *o = GBIT16(p), p+=2;
+ *o = GBIT16(p) - (2+256*3), p+=2;
for(w=f->w; w < f->w+nelem(f->w); w++)
*w = *p++;
n -= p-u;
--- a/inter.c
+++ b/inter.c
@@ -889,118 +889,6 @@
VW_UpdateScreen ();
}
-
-//==========================================================================
-
-/*
-==================
-=
-= DrawHighScores
-=
-==================
-*/
-
-void DrawHighScores(void)
-{
- char buffer[16],*str,buffer1[5];
- u8int temp,temp1,temp2,temp3;
- u16int i,j,
- w,h,
- x,y;
- HighScore *s;
-
-#ifndef SPEAR
- fontnumber=0;
-#else
- fontnumber = 1;
-#endif
-
-
-#ifndef SPEAR
- SETFONTCOLOR(15,0x29);
-#else
- SETFONTCOLOR(HIGHLIGHT,0x29);
-#endif
-
- for (i = 0,s = Scores;i < MaxScores;i++,s++)
- {
- PrintY = 76 + (16 * i);
-
- //
- // name
- //
-#ifndef SPEAR
- PrintX = 4*8;
-#else
- PrintX = 16;
-#endif
- US_Print(s->name);
-
- //
- // level
- //
- ultoa(s->completed,buffer,10);
-#ifndef SPEAR
- for (str = buffer;*str;str++)
- *str = *str + (129 - '0'); // Used fixed-width numbers (129...)
- USL_MeasureString(buffer,&w,&h);
- PrintX = (22 * 8)-w;
-#else
- USL_MeasureString(buffer,&w,&h);
- PrintX = 194 - w;
-#endif
-
-#ifndef UPLOAD
-#ifndef SPEAR
- PrintX -= 6;
- itoa(s->episode+1,buffer1,10);
- US_Print("E");
- US_Print(buffer1);
- US_Print("/L");
-#endif
-#endif
-
-#ifdef SPEAR
- if (s->completed == 21)
- VWB_DrawPic (PrintX+8,PrintY-1,Pspear);
- else
-#endif
- US_Print(buffer);
-
- //
- // score
- //
- ultoa(s->score,buffer,10);
-#ifndef SPEAR
- for (str = buffer;*str;str++)
- *str = *str + (129 - '0'); // Used fixed-width numbers (129...)
- USL_MeasureString(buffer,&w,&h);
- PrintX = (34 * 8) - 8 - w;
-#else
- USL_MeasureString(buffer,&w,&h);
- PrintX = 292 - w;
-#endif
- US_Print(buffer);
- }
-
- VW_UpdateScreen ();
-
-#ifdef SPEAR
- fontnumber = 0;
-#endif
-}
-
-//===========================================================================
-
-
-/*
-=======================
-=
-= CheckHighScore
-=
-=======================
-*/
-
void CheckHighScore (s32int score,u16int other)
{
u16int i,j;
--- a/mn.c
+++ b/mn.c
@@ -3,6 +3,23 @@
#include "dat.h"
#include "fns.h"
+typedef struct Score Score;
+struct Score{
+ char name[58];
+ int n;
+ int lvl;
+ int ep;
+};
+static Score score[] = {
+ {"id software-'92", 10000, 1},
+ {"Adrian Carmack", 10000, 1},
+ {"John Carmack", 10000, 1},
+ {"Kevin Cloud", 10000, 1},
+ {"Tom Hall", 10000, 1},
+ {"John Romero", 10000, 1},
+ {"Jay Wilbur", 10000, 1},
+};
+
static void (*clear)(void);
static void (*stripe)(int);
static void (*scores)(void);
@@ -49,20 +66,70 @@
}
static void
+fixedw(char *s)
+{
+ char c;
+
+ while(c = *s, c != 0)
+ *s++ = c - '0' + 129;
+}
+
+static void
wlscores(void)
{
+ int x, y;
+ char a[16], b[16];
+ Score *s;
+
clear();
stripe(10);
pic(48, 0, pict[Pscores]);
- pic(4*8, 68, pict[Pname]);
- pic(20*8, 68, pict[Plvl]);
- pic(28*8, 68, pict[Phigh]);
+ pic(32, 68, pict[Pname]);
+ pic(160, 68, pict[Plvl]);
+ pic(224, 68, pict[Phigh]);
+
+ fnt = fnts;
+ for(s=score, y=76; s<score+nelem(score); s++, y+=16){
+ txt(32, y, s->name, 0xf);
+
+ sprint(a, "%d", s->lvl);
+ fixedw(a);
+ x = 176 - txtw(a);
+ if(ver < WL1){
+ sprint(b, "E%d/L", s->ep+1);
+ x += txt(x-6, y, b, 0xf) - 6;
+ }
+ txt(x, y, a, 0xf);
+
+ sprint(a, "%d", s->n);
+ fixedw(a);
+ txt(264 - txtw(a), y, a, 0xf);
+ }
}
static void
sdscores(void)
{
+ int y;
+ char a[16];
+ Score *s;
+
clear();
pic(0, 0, pict[Pscores]);
+
+ fnt = fnts+1;
+ for(s=score, y=76; s<score+nelem(score); s++, y+=16){
+ txt(16, y, s->name, 0x13);
+
+ if(s->lvl == 21)
+ pic(176, y-1, pict[Pspear]);
+ else{
+ sprint(a, "%d", s->lvl);
+ txt(194 - txtw(a), y, a, 0xf);
+ }
+
+ sprint(a, "%d", s->n);
+ txt(292 - txtw(a), y, a, 0xf);
+ }
}
static void
--- a/rend.c
+++ b/rend.c
@@ -3,7 +3,7 @@
#include "dat.h"
#include "fns.h"
-Fnt fnts[2];
+Fnt fnts[2], *fnt;
Pic *pics, *pice;
Dat *exts, *exte;
Dat *dems, *deme, *epis;
@@ -132,6 +132,65 @@
memset(d, c, dx);
d += Vw;
}
+}
+
+int
+txt(int x, int y, char *t, int col)
+{
+ int h, w;
+ uchar c, *d, *s, *p, *e, *q;
+
+ h = fnt->h;
+ p = fnt->p;
+ c = *t++;
+ d = pxb + x + y*Vw;
+ x = 0;
+ while(c != 0){
+ w = fnt->w[c];
+ s = p + fnt->ofs[c];
+ e = s + w*h;
+ while(s < e){
+ q = s + w;
+ while(s < q){
+ c = *s++;
+ if(c != 0)
+ *d = col;
+ d++;
+ }
+ d += Vw-w;
+ }
+ d -= Vw*h - w;
+ x += w;
+ c = *t++;
+ }
+ return x;
+}
+
+int
+txtnl(int x, int y, char *t, int col)
+{
+ int n;
+ char *s;
+
+ n = 0;
+ s = strtok(t, "\n");
+ while(s != nil){
+ n += txt(x, y, s, col);
+ s = strtok(nil, "\n");
+ y += fnt->h;
+ }
+ return n;
+}
+
+int
+txtw(char *t)
+{
+ int n;
+
+ n = 0;
+ while(*t != 0)
+ n += fnt->w[(uchar)*t++];
+ return n;
}
void
--- a/us.h
+++ b/us.h
@@ -94,7 +94,6 @@
US_StartCursor(void),
US_ShutCursor(void),
US_CheckHighScore(s32int score,u16int other),
- US_DisplayHighScores(s16int which);
extern int US_UpdateCursor(void),
US_LineInput(s16int x,s16int y,char *buf,char *def,int escok,
s16int maxchars,s16int maxwidth);
--- a/us1.c
+++ b/us1.c
@@ -11,16 +11,6 @@
(*USL_DrawString)(char far *) = VWB_DrawPropString;
SaveGame Games[MaxSaveGames];
- HighScore Scores[MaxScores] =
- {
- {"id software-'92",10000,1},
- {"Adrian Carmack",10000,1},
- {"John Carmack",10000,1},
- {"Kevin Cloud",10000,1},
- {"Tom Hall",10000,1},
- {"John Romero",10000,1},
- {"Jay Wilbur",10000,1},
- };
// Window/Printing routines
--- a/vh.c
+++ b/vh.c
@@ -13,144 +13,6 @@
s16int bufferwidth,bufferheight;
-//==========================================================================
-
-void VWL_UpdateScreenBlocks (void);
-
-//==========================================================================
-
-void VW_DrawPropString (char far *string)
-{
- fontstruct far *font;
- s16int width,step,height,i;
- u8int far *source, far *dest, far *origdest;
- u8int ch,mask;
-
- font = (fontstruct far *)grsegs[STARTFONT+fontnumber];
- height = bufferheight = font->height;
- dest = origdest = MK_FP(SCREENSEG,bufferofs+ylookup[py]+(px>>2));
- mask = 1<<(px&3);
-
-
- while ((ch = *string++)!=0)
- {
- width = step = font->width[ch];
- source = ((u8int far *)font)+font->location[ch];
- while (width--)
- {
- VGAMAPMASK(mask);
-
-asm mov ah,[BYTE PTR fontcolor]
-asm mov bx,[step]
-asm mov cx,[height]
-asm mov dx,[linewidth]
-asm lds si,[source]
-asm les di,[dest]
-
-vertloop:
-asm mov al,[si]
-asm or al,al
-asm je next
-asm mov [es:di],ah // draw color
-
-next:
-asm add si,bx
-asm add di,dx
-asm loop vertloop
-asm mov ax,ss
-asm mov ds,ax
-
- source++;
- px++;
- mask <<= 1;
- if (mask == 16)
- {
- mask = 1;
- dest++;
- }
- }
- }
-bufferheight = height;
-bufferwidth = ((dest+1)-origdest)*4;
-}
-
-
-void VW_DrawColorPropString (char far *string)
-{
- fontstruct far *font;
- s16int width,step,height,i;
- u8int far *source, far *dest, far *origdest;
- u8int ch,mask;
-
- font = (fontstruct far *)grsegs[STARTFONT+fontnumber];
- height = bufferheight = font->height;
- dest = origdest = MK_FP(SCREENSEG,bufferofs+ylookup[py]+(px>>2));
- mask = 1<<(px&3);
-
-
- while ((ch = *string++)!=0)
- {
- width = step = font->width[ch];
- source = ((u8int far *)font)+font->location[ch];
- while (width--)
- {
- VGAMAPMASK(mask);
-
-asm mov ah,[BYTE PTR fontcolor]
-asm mov bx,[step]
-asm mov cx,[height]
-asm mov dx,[linewidth]
-asm lds si,[source]
-asm les di,[dest]
-
-vertloop:
-asm mov al,[si]
-asm or al,al
-asm je next
-asm mov [es:di],ah // draw color
-
-next:
-asm add si,bx
-asm add di,dx
-
-asm rcr cx,1 // inc font color
-asm jc cont
-asm inc ah
-
-cont:
-asm rcl cx,1
-asm loop vertloop
-asm mov ax,ss
-asm mov ds,ax
-
- source++;
- px++;
- mask <<= 1;
- if (mask == 16)
- {
- mask = 1;
- dest++;
- }
- }
- }
-bufferheight = height;
-bufferwidth = ((dest+1)-origdest)*4;
-}
-
-void VWL_MeasureString (char far *string, u16int *width, u16int *height
- , fontstruct _seg *font)
-{
- *height = font->height;
- for (*width = 0;*string;string++)
- *width += font->width[*((u8int far *)string)]; // proportional width
-}
-
-void VW_MeasurePropString (char far *string, u16int *width, u16int *height)
-{
- VWL_MeasureString(string,width,height,(fontstruct _seg *)grsegs[STARTFONT+fontnumber]);
-}
-
-
/*
=============================================================================
@@ -222,47 +84,10 @@
LatchDrawChar(x,y,tile);
}
-void VWB_DrawPic (s16int x, s16int y, s16int chunknum)
-{
- s16int picnum = chunknum - STARTPICS;
- u16int width,height;
-
- x &= ~7;
-
- width = pictable[picnum].width;
- height = pictable[picnum].height;
-
- if (VW_MarkUpdateBlock (x,y,x+width-1,y+height-1))
- VL_MemToScreen (grsegs[chunknum],width,height,x,y);
-}
-
-
-
-void VWB_DrawPropString (char far *string)
-{
- s16int x;
- x=px;
- VW_DrawPropString (string);
- VW_MarkUpdateBlock(x,py,px-1,py+bufferheight-1);
-}
-
-
-void VWB_Bar (s16int x, s16int y, s16int width, s16int height, s16int color)
-{
- if (VW_MarkUpdateBlock (x,y,x+width,y+height-1) )
- VW_Bar (x,y,width,height,color);
-}
-
void VWB_Plot (s16int x, s16int y, s16int color)
{
if (VW_MarkUpdateBlock (x,y,x,y))
VW_Plot(x,y,color);
-}
-
-void VWB_Hlin (s16int x1, s16int x2, s16int y, s16int color)
-{
- if (VW_MarkUpdateBlock (x1,y,x2,y))
- VW_Hlin(x1,x2,y,color);
}
void VWB_Vlin (s16int y1, s16int y2, s16int x, s16int color)
--- a/vl.c
+++ b/vl.c
@@ -51,136 +51,7 @@
}
}
-//===========================================================================
-
/*
-=================
-=
-= VL_SetColor
-=
-=================
-*/
-
-void VL_SetColor (s16int color, s16int red, s16int green, s16int blue)
-{
- outportb (PEL_WRITE_ADR,color);
- outportb (PEL_DATA,red);
- outportb (PEL_DATA,green);
- outportb (PEL_DATA,blue);
-}
-
-//===========================================================================
-
-/*
-=================
-=
-= VL_GetColor
-=
-=================
-*/
-
-void VL_GetColor (s16int color, s16int *red, s16int *green, s16int *blue)
-{
- outportb (PEL_READ_ADR,color);
- *red = inportb (PEL_DATA);
- *green = inportb (PEL_DATA);
- *blue = inportb (PEL_DATA);
-}
-
-/*
-=================
-=
-= VL_FadeOut
-=
-= Fades the current palette to the given color in the given number of steps
-=
-=================
-*/
-
-void VL_FadeOut (s16int start, s16int end, s16int red, s16int green, s16int blue, s16int steps)
-{
- s16int i,j,orig,delta;
- u8int far *origptr, far *newptr;
-
- VL_WaitVBL(1);
- VL_GetPalette (&palette1[0][0]);
- _fmemcpy (palette2,palette1,768);
-
-//
-// fade through intermediate frames
-//
- for (i=0;i<steps;i++)
- {
- origptr = &palette1[start][0];
- newptr = &palette2[start][0];
- for (j=start;j<=end;j++)
- {
- orig = *origptr++;
- delta = red-orig;
- *newptr++ = orig + delta * i / steps;
- orig = *origptr++;
- delta = green-orig;
- *newptr++ = orig + delta * i / steps;
- orig = *origptr++;
- delta = blue-orig;
- *newptr++ = orig + delta * i / steps;
- }
-
- VL_WaitVBL(1);
- VL_SetPalette (&palette2[0][0]);
- }
-
-//
-// final color
-//
- VL_FillPalette (red,green,blue);
-
- screenfaded = true;
-}
-
-
-/*
-=================
-=
-= VL_FadeIn
-=
-=================
-*/
-
-void VL_FadeIn (s16int start, s16int end, u8int far *palette, s16int steps)
-{
- s16int i,j,delta;
-
- VL_WaitVBL(1);
- VL_GetPalette (&palette1[0][0]);
- _fmemcpy (&palette2[0][0],&palette1[0][0],sizeof(palette1));
-
- start *= 3;
- end = end*3+2;
-
-//
-// fade through intermediate frames
-//
- for (i=0;i<steps;i++)
- {
- for (j=start;j<=end;j++)
- {
- delta = palette[j]-palette1[0][j];
- palette2[0][j] = palette1[0][j] + delta * i / steps;
- }
-
- VL_WaitVBL(1);
- VL_SetPalette (&palette2[0][0]);
- }
-
-//
-// final color
-//
- VL_SetPalette (palette);
- screenfaded = false;
-}
-
-/*
==================
=
= VL_ColorBorder
@@ -227,51 +98,6 @@
mask = pixmasks[x&3];
VGAMAPMASK(mask);
*(u8int far *)MK_FP(SCREENSEG,bufferofs+(ylookup[y]+(x>>2))) = color;
- VGAMAPMASK(15);
-}
-
-
-/*
-=================
-=
-= VL_Hlin
-=
-=================
-*/
-
-void VL_Hlin (u16int x, u16int y, u16int width, u16int color)
-{
- u16int xbyte;
- u8int far *dest;
- u8int leftmask,rightmask;
- s16int midbytes;
-
- xbyte = x>>2;
- leftmask = leftmasks[x&3];
- rightmask = rightmasks[(x+width-1)&3];
- midbytes = ((x+width+3)>>2) - xbyte - 2;
-
- dest = MK_FP(SCREENSEG,bufferofs+ylookup[y]+xbyte);
-
- if (midbytes<0)
- {
- // all in one byte
- VGAMAPMASK(leftmask&rightmask);
- *dest = color;
- VGAMAPMASK(15);
- return;
- }
-
- VGAMAPMASK(leftmask);
- *dest++ = color;
-
- VGAMAPMASK(15);
- _fmemset (dest,color,midbytes);
- dest+=midbytes;
-
- VGAMAPMASK(rightmask);
- *dest = color;
-
VGAMAPMASK(15);
}