// -------------------------------------------------------------------------------------
// Print char function
void PrintCharXY(int iPx0,int iPy0, char cChr)
{
unsigned short _iFont3x5[128]={
3960, //Character 000 [NUL
3960, //Character 001 [SOH
3960, //Character 002 [STX]
3960, //Character 003 [ETX]
3960, //Character 004 [EOT]
3960, //Character 005 [ENQ]
3960, //Character 006 [ACK]
3960, //Character 007 BEL]
3960, //Character 008 BS]
3960, //Character 009 [TAB]
3960, //Character 010 [LF]
3960, //Character 011 [VT]
32000, //Character 012 [FF]
3960, //Character 013 [CR]
3960, //Character 014 [SO]
3960, //Character 015 [SI]
3960, //Character 016 [DEL]
3960, //Character 017 [XON]
3960, //Character 018 [DC2]
3960, //Character 019 [XOFF]
3960, //Character 020 [DC4]
3960, //Character 021 [NAK]
3960, //Character 022 [SYN]
3960, //Character 023 [ETB]
3960, //Character 024 [CAN]
3960, //Character 025 [EM]
3960, //Character 026 [SUB]
3960, //Character 027 [ESC]
3960, //Character 028 [FS]
3960, //Character 029 [GS]
3960, //Character 030 [RS]
3960, //Character 031 US
0, //Character 032 [SP]
8338, //Character 033 [!]
45, //Character 034 ["]
16254, //Character 035 [#]
32223, //Character 036 [$]
21157, //Character 037 [%]
10922, //Character 038 [&]
166, //Character 039 [']
17556, //Character 040 [(]
5265, //Character 041 [)]
2728, //Character 042 [*]
1488, //Character 043 [+]
10624, //Character 044 [,]
448, //Character 045 [-]
13824, //Character 046 [.]
4756, //Character 047 [/]
31599, //Character 048 [0]
29850, //Character 049 [1]
29671, //Character 050 [2]
31207, //Character 051 [3]
18925, //Character 052 [4]
31183, //Character 053 [5]
31695, //Character 054 [6]
18727, //Character 055 [7]
31727, //Character 056 [8]
31215, //Character 057 [9]
13851, //Character 058 [:]
5147, //Character 059 [;]
17492, //Character 060 [<]
3640, //Character 061 [=]
5393, //Character 062 [>]
8355, //Character 063 [?]
11171, //Character 064 [@]
23530, //Character 065 [A]
15083, //Character 066 B]
25166, //Character 067 [C]
15211, //Character 068 [D]
29647, //Character 069 [E]
5071, //Character 070 [F]
27470, //Character 071 [G]
23533, //Character 072 [H]
29847, //Character 073 I
11044, //Character 074 [J]
23277, //Character 075 [K]
29257, //Character 076 [L]
23421, //Character 077 [M]
23403, //Character 078 [N]
11114, //Character 079 [O]
4843, //Character 080 [P]
17770, //Character 081 [Q]
23275, //Character 082 [R]
14478, //Character 083 [S]
9367, //Character 084 [T]
31597, //Character 085 U
11117, //Character 086 [V]
12141, //Character 087 [W]
23213, //Character 088 [X]
9389, //Character 089 [Y]
29351, //Character 090 [Z]
25750, //Character 091 [[]
17545, //Character 092 \
26918, //Character 093 []]
42, //Character 094 [^]
28672, //Character 095 [_]
139, //Character 096 [`]
27554, //Character 097 [a]
15225, //Character 098 b]
25200, //Character 099 [c]
27516, //Character 100 [d]
29674, //Character 101 [e]
9684, //Character 102 [f]
14766, //Character 103 [g]
23385, //Character 104 [h]
9346, //Character 105 i
11012, //Character 106 [j]
22345, //Character 107 [k]
29843, //Character 108 [l]
23408, //Character 109 [m]
23376, //Character 110 [n]
11088, //Character 111 [o]
5976, //Character 112 [p]
19824, //Character 113 [q]
4840, //Character 114 [r]
14448, //Character 115 [s]
17586, //Character 116 [t]
27496, //Character 117 u
11112, //Character 118 [v]
32616, //Character 119 [w]
23208, //Character 120 [x]
5480, //Character 121 [y]
29496, //Character 122 [z]
25814, //Character 123 [{]
9362, //Character 124 [|]
13715, //Character 125 [}]
408, //Character 126 [~]
3960 //Character 127 []
}; //Variables
int i,j;
int iPx,iPy;
int iAy,iAx;
unsigned int iCount;
unsigned int iBitmap;
char sStr[2];
unsigned char cChr0;
cChr0=cChr;
cChr0=(cChr0<=126?cChr0:127);
iPx=iPx0;
iPy=iPy0;
//Print loop
iCount = 1;
iAx=4;
iAy=6;
iBitmap=_iFont3x5[cChr0];
for(j=0;j<5;j++){
for(i=0;i<=3;i++){
if(iPx+i>=0 && iPx+i<=127 && iPy+j>=0 && iPy+j<=63)
{
if(i<iAx-1 && j<iAy-1)
{
if(iBitmap&iCount)
ML_pixel(iPx+i,iPy+j,1);
else
ML_pixel(iPx+i,iPy+j,0);
iCount=iCount*2;
}
else
ML_pixel(iPx+i,iPy+j,0);
}
}
}
}
// -------------------------------------------------------------------------------------
// Print string function (location by pixels)
void PrintStr(int iPx, int iPy,char *sStr)
{
//Variables
int i;
int iPx0=0,iPy0=0;
int iIgnChar=0;
char cChr;
//Char loop
for(i=0;sStr[ i ]!=0;i++)
{
PrintCharXY(iPx+4*(i-iIgnChar),iPy,sStr[ i ]);
}
}
#define SCA 0xD201D002
#define SCB 0x422B0009
#define SCE 0x80010070
typedef int(*sc_i2cp2sip) (char*, char*, short int*, short int*);
typedef int(*sc_iv) (void);
typedef int(*sc_4i) (int, int, int);
const unsigned int sc003b[] = {SCA, SCB, SCE, 0x3B};
const unsigned int sc0015[] = {SCA, SCB, SCE, 0x15};
const unsigned int sc0248[] = {SCA, SCB, SCE, 0x248};
#define RTC_GetTicks (*(sc_iv)sc003b)
#define PutKey (*(sc_4i)sc0248)
#define GlibGetOSVersionInfo (*(sc_i2cp2sip)sc0015)
int OSVersionAsInt(void)
{
unsigned char mainversion;
unsigned char minorversion;
unsigned short release;
unsigned short build;
GlibGetOSVersionInfo( &mainversion, &minorversion, &release, &build );
return ( ( mainversion << 24 ) & 0xFF000000 ) | ( ( minorversion << 16 ) & 0x00FF0000 ) | ( release & 0x0000FFFF );
}
#define isOS2 (OSVersionAsInt() >= 0x02020000)
#define OS2(x,y) ((OSVersionAsInt() >= 0x02020000)?y:x)
static void delay()
{
unsigned char i;
for(i=0 ; i<5 ; i++);
}
unsigned char CheckKeyRow(unsigned char code)
{
unsigned char result=0;
short*PORTB_CTRL=(void*)0xA4000102;
short*PORTM_CTRL=(void*)0xA4000118;
char*PORTB=(void*)0xA4000122;
char*PORTM=(void*)0xA4000138;
char*PORTA=(void*)0xA4000120;
short smask;
char cmask;
unsigned char column, row;
column = code>>4;
row = code &0x0F;
smask = 0x0003 << (( row %8)*2);
cmask = ~( 1 << ( row %8) );
if(row <8)
{
*PORTB_CTRL = 0xAAAA ^ smask;
*PORTM_CTRL = (*PORTM_CTRL & 0xFF00 ) | 0x00AA;
delay();
*PORTB = cmask;
*PORTM = (*PORTM & 0xF0 ) | 0x0F;
}
else
{
*PORTB_CTRL = 0xAAAA;
*PORTM_CTRL = ((*PORTM_CTRL & 0xFF00 ) | 0x00AA) ^ smask;
delay();
*PORTB = 0xFF;
*PORTM = (*PORTM & 0xF0 ) | cmask;
}
delay();
result = (~(*PORTA))>>column & 1;
delay();
*PORTB_CTRL = 0xAAAA;
*PORTM_CTRL = (*PORTM_CTRL & 0xFF00 ) | 0x00AA;
delay();
*PORTB_CTRL = 0x5555;
*PORTM_CTRL = (*PORTM_CTRL & 0xFF00 ) | 0x0055;
delay();
return result;
}
unsigned char key_down(unsigned char code)
{
unsigned short key[8];
const unsigned short* keyboardregister = (unsigned short*)0xA44B0000;
unsigned char row;
if(isOS2)
{
memcpy(&key, keyboardregister, sizeof(unsigned short) << 3);
row= code%10;
return (0 != (key[row >> 1] & 1 << code / 10 - 1 + ((row & 1) << 3)));
}
else
{
return CheckKeyRow((code % 10) + ((code / 10 - 1) << 4));
}
}
char* inputString(char* message,int tailleMax)
{
int a;
int endroit = 0;
int curseurX = 0;
int curseurY = 0;
int ecran=0;
int wich;
int touche[]={K_XT,K_LOG,K_LN,K_SIN,K_COS,K_TAN,K_FRAC,K_FD,K_LPAR,K_RPAR,K_COMMA,K_STORE,K_7,K_8,K_9,K_4,K_5,K_6,K_MULT,K_DIV,K_1,K_2,K_3,K_PLUS,K_MINUS,K_0,K_DP};
int touche2[]={K_1,K_2,K_3,K_DP,K_COMMA,0,0,0,0,K_4,K_5,K_6,K_PLUS,K_MINUS,K_MULT,K_DIV,0,0,K_7,K_8,K_9,K_0,K_POW,K_LPAR,K_RPAR,0,0};
unsigned char fleche[] = {0xC0, 0xE0, 0xF0, 0xE0, 0xC0};
char texte[3][27]={"abcdefghijklmnopqrstuvwxyz ","ABCDEFGHIJKLMNOPQRSTUVWXYZ ","123.,;:!?456+-*/'|7890^()\ "};
char mot[40]={0};
for(a = 0;a<tailleMax;a++)mot[a]='_';
while(1)
{
if(key_down(K_UP) && curseurY)curseurY--;
if(key_down(K_DOWN) && curseurY<2)curseurY++;
if(key_down(K_LEFT) && curseurX)curseurX--;
if(key_down(K_RIGHT) && curseurX<9)curseurX++;
if(key_down(K_ALPHA)){if(ecran == 0)ecran = 1;else ecran =0;while(key_down(K_ALPHA))Sleep(5);}
if(key_down(K_SHIFT)){if(ecran == 0)ecran = 2;else ecran =0;while(key_down(K_SHIFT))Sleep(5);}
if(key_down(K_PMINUS) || key_down(K_DEL))
{
if(endroit)
{
endroit--;
mot[endroit]='_';
}
while(key_down(K_DEL) || key_down(K_PMINUS))Sleep(5);
}
if(key_down(K_EXE))
{
if(curseurX==9)
{
if(curseurY == 0)if(ecran == 0)ecran = 1; else ecran = 0;
if(curseurY == 1)if(ecran == 0)ecran = 2; else ecran = 0;
if(curseurY == 2)return mot;
}
else
{
if(ecran == 0 && curseurX == 8 && curseurY == 2)
{
if(endroit)
{
endroit--;
mot[endroit]='_';
}
}
else if(endroit<tailleMax)
{
mot[endroit]=texte[ecran][curseurX+curseurY*9];
endroit++;
}
}
while(key_down(K_EXE))Sleep(5);
}
if(ecran<2)
{
for(a=0;a<27;a++)if(key_down(touche[a])){mot[endroit]=texte[ecran][a];endroit++;while(key_down(touche[a]))Sleep(5);}
}
else for(a=0;a<27;a++)if(key_down(touche2[a])){mot[endroit]=texte[ecran][a];endroit++;while(key_down(touche2[a]))Sleep(5);}
afficheFenetre(11); // affiche une petite fenetre de 0;0 a 128;22
afficheFenetre(12); // affiche une grande fenetre de 0;22 a 128;64
PrintStr(10,6,message);
PrintStr(10,12,mot);
PrintStr(100,48,"fin");
PrintStr(100,30,"maj");
PrintStr(100,39,"num");
for(a =0;a<26;a++)PrintCharXY(10+(a%9)*10,30+9*(a>8)+9*(a>17),texte[ecran][a]);
if(ecran == 0)
{
ML_line(90,50,94,50,ML_BLACK);
ML_line(90,50,92,48,ML_BLACK);
ML_line(90,50,92,52,ML_BLACK);
}
ML_bmp_or(fleche,curseurX*10+5,curseurY*9+30,5,5);
ML_display_vram();
ML_clear_vram();
Sleep(150);
}
}
Citer : Posté le 20/05/2013 23:04 | #
Les 3/4 du code servent à gérer le clavier.
Dans une fonction qui doit attendre l'appui d'une touche pour faire quelque chose, pourquoi ne pas utiliser GetKey ?
Citer : Posté le 21/05/2013 07:34 | #
personnellement, je n'aime pas beaucoup GetKey, parce que l'utilisateur peut quitter le programme, et que je trouve le passage par pointeur bizarre.
envie de plonger dans la mer pour ramasser des tresors? => ballon sea
envie de sauver l'univers dans un jeu avec une longue durée de vie? => saviors of the future
un add-in addictif avec plein de secret et de trophées => evasion survival
un shmup bien dur et sadique => saviors 2
merci a tout le monde pour son soutien
zelda prizm de smashmaster (en esperant qu'il puisse le finir)
les tests de marmotti
un RPG de dark storm
(dont je connais le nom, mais pas vous )Arcuz !Citer : Posté le 21/05/2013 17:07 | #
c'est justement pratique de pouvoir quitter l'add-in… (ou d'éteindre la calto)